Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1f2030f
Enum for Car Type
luyounus Jan 2, 2018
fc6338b
Initial commit
luyounus Jan 2, 2018
f551fd5
Car Type Enum created
luyounus Jan 2, 2018
fb623d4
Car class implemented
luyounus Jan 2, 2018
f93d0fa
Add method implemented
luyounus Jan 2, 2018
ab680cc
Remove and AtIndex methods implemented
luyounus Jan 2, 2018
46023e8
Remove Method fixed
luyounus Jan 2, 2018
e1b4e75
last update
luyounus Jan 2, 2018
bee16ec
Product Type Enum
luyounus Jan 3, 2018
139dbb3
Product Class that holds name and product type
luyounus Jan 3, 2018
680188a
Inventory class created with Enumerator methods
luyounus Jan 3, 2018
b6a6ca2
Adding item to the inventory
luyounus Jan 3, 2018
b6b6bf1
Remove product in inventory method removed
luyounus Jan 3, 2018
a4898ac
Get index of product at inventory
luyounus Jan 3, 2018
a8c9876
Adding products to Generic List
luyounus Jan 3, 2018
3d90d6f
View all products in inventory
luyounus Jan 3, 2018
c5076e6
The Inventory is ready to use!
luyounus Jan 3, 2018
2e09d7f
Xunit project addition
luyounus Jan 3, 2018
88943c2
Removed empty extra projects
luyounus Jan 3, 2018
afcf415
Changed Access Modifiers to public to allow unit testing
luyounus Jan 3, 2018
3e7f13a
Xunit first test passing
luyounus Jan 3, 2018
afc4365
Fixed Resizing Inventory Array after removing
luyounus Jan 3, 2018
4252145
Second test written
luyounus Jan 3, 2018
471918b
Last test written with Exception
luyounus Jan 3, 2018
8b7213b
Array size Modifications
luyounus Jan 3, 2018
b06bcbd
Modifictation in the test file
luyounus Jan 3, 2018
a2aa472
Readme updated
luyounus Jan 3, 2018
e1d6fa4
Readme Update
luyounus Jan 3, 2018
f2d2e06
Readme fixed
luyounus Jan 3, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions EcommerceStore/EcommerceStore.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EcommerceStore", "EcommerceStore\EcommerceStore.csproj", "{99A9498F-9D77-47EB-8E8A-E3F538308F0A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitTestEcommerceStore", "XUnitTestEcommerceStore\XUnitTestEcommerceStore.csproj", "{C33C2553-233D-4F71-8424-13FCB671EBBE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{99A9498F-9D77-47EB-8E8A-E3F538308F0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99A9498F-9D77-47EB-8E8A-E3F538308F0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99A9498F-9D77-47EB-8E8A-E3F538308F0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99A9498F-9D77-47EB-8E8A-E3F538308F0A}.Release|Any CPU.Build.0 = Release|Any CPU
{C33C2553-233D-4F71-8424-13FCB671EBBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C33C2553-233D-4F71-8424-13FCB671EBBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C33C2553-233D-4F71-8424-13FCB671EBBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C33C2553-233D-4F71-8424-13FCB671EBBE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9F34F094-1B4E-4384-BD73-EB8FA36453C1}
EndGlobalSection
EndGlobal
84 changes: 84 additions & 0 deletions EcommerceStore/EcommerceStore/Classes/Inventory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace EcommerceStore.Classes
{
public class Inventory<T> : IEnumerable<T>
{
public T[] Items = new T[2];
public int Count = 0;

public void Add(T item)
{
if (Count == (Items.Length / 2))
{
T[] newArray = new T[Items.Length * 2];

for (int i = 0; i < Items.Length; i++)
{
newArray[i] = Items[i];
}

Items = newArray;
}
Items[Count] = item;
Count++;
}

public void Remove(T item)
{
T[] newArray = new T[Items.Length];
if (Count - 1 <= Items.Length / 2)
{
newArray = new T[Items.Length / 2];
}

int j = 0;
int tempCount = Count;
for (int i = 0; i < tempCount; i++)
{
if (j >= tempCount) break;
if (!item.Equals(Items[j]))
{
newArray[i] = Items[j];
j++;
}
else
{
Count--;
i--;
j++;
}
}
Items = newArray;
}

public int AtIndexOf(T item)
{
for (int i = 0; i < Count; i++)
{
if (Items[i].Equals(item))
{
return i;
}
}
throw new InvalidOperationException();
}

public IEnumerator<T> GetEnumerator()
{
for (int i = 0; i < Count; i++)
{
yield return Items[i];
}
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}
18 changes: 18 additions & 0 deletions EcommerceStore/EcommerceStore/Classes/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace EcommerceStore.Classes
{
public class Product
{
public string Name { get; set; }
public ProductType Type { get; set; }

public Product(string name, ProductType type)
{
Name = name;
Type = type;
}
}
}
10 changes: 10 additions & 0 deletions EcommerceStore/EcommerceStore/Classes/ProductType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace EcommerceStore.Classes
{
public enum ProductType
{
Movies,
Home,
Health,
Grocery
}
}
12 changes: 12 additions & 0 deletions EcommerceStore/EcommerceStore/EcommerceStore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.3.1" />
</ItemGroup>

</Project>
75 changes: 75 additions & 0 deletions EcommerceStore/EcommerceStore/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using EcommerceStore.Classes;

namespace EcommerceStore
{
class Program
{
static void Main(string[] args)
{
Product product1 = new Product("Chocolate", ProductType.Grocery);
Product product2 = new Product("Apple", ProductType.Grocery);
Product product3 = new Product("Milk", ProductType.Grocery);
Product product4 = new Product("Banana", ProductType.Grocery);
Product product5 = new Product("JAWS", ProductType.Movies);
Product product6 = new Product("Titanic", ProductType.Movies);
Product product7 = new Product("Star Wars", ProductType.Movies);
Product product8 = new Product("Batman", ProductType.Movies);
Product product9 = new Product("Tooth Paste", ProductType.Health);
Product product10 = new Product("Band Aids", ProductType.Health);

List<Product> productsList = new List<Product>
{
product1, product2, product3, product4, product5, product6, product7, product8, product9, product10
};

Console.WriteLine("\n Using List Add Method");
Console.WriteLine("------------------------------------------------------------------------");

// Adding 10 Items with List.Add
Console.WriteLine("\n Adding 10 items to Inventory");
ViewAllProducts(productsList);

// Removing Health Products with List.Remove
Console.WriteLine("\n Removing Health Products");
productsList.Remove(product9);
productsList.Remove(product10);
ViewAllProducts(productsList);

Inventory<Product> inventory = new Inventory<Product>();

Console.WriteLine("\n Using Inventory Add, Remove, AtIndex methods");
Console.WriteLine("------------------------------------------------------------------------");

// Adding 10 Items with Inventory.Add
Console.WriteLine("\n Adding 10 items to Inventory");
inventory.Add(product1); inventory.Add(product2); inventory.Add(product3); inventory.Add(product4); inventory.Add(product5);
inventory.Add(product6); inventory.Add(product7); inventory.Add(product8); inventory.Add(product9); inventory.Add(product10);
ViewAllProducts(inventory.Items.OfType<Product>().ToList());

// Removing Health Products with Inventory.Remove
Console.WriteLine("\n Removing Health Products");
inventory.Remove(product9);
inventory.Remove(product10);
ViewAllProducts(inventory.Items.OfType<Product>().ToList());

// Finding Batman Index
Console.WriteLine("\n Getting Index of Batman Movie");
Console.WriteLine("-------------------------------");
Console.WriteLine(" The index is: {0}", inventory.AtIndexOf(product8));

Console.ReadLine();
}

public static void ViewAllProducts(List<Product> products)
{
Console.WriteLine("-------------------------------");
foreach (Product p in products)
{
Console.WriteLine(" " + p.Name + " - " + p.Type);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v2.0",
"signature": "9f73f47f96268db03c3857a6003f7c4743dcd996"
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v2.0": {
"EcommerceStore/1.0.0": {
"dependencies": {
"xunit": "2.3.1"
},
"runtime": {
"EcommerceStore.dll": {}
}
},
"xunit/2.3.1": {
"dependencies": {
"xunit.analyzers": "0.7.0",
"xunit.assert": "2.3.1",
"xunit.core": "2.3.1"
}
},
"xunit.abstractions/2.0.1": {
"runtime": {
"lib/netstandard1.0/xunit.abstractions.dll": {}
}
},
"xunit.analyzers/0.7.0": {},
"xunit.assert/2.3.1": {
"runtime": {
"lib/netstandard1.1/xunit.assert.dll": {}
}
},
"xunit.core/2.3.1": {
"dependencies": {
"xunit.extensibility.core": "2.3.1",
"xunit.extensibility.execution": "2.3.1"
}
},
"xunit.extensibility.core/2.3.1": {
"dependencies": {
"xunit.abstractions": "2.0.1"
},
"runtime": {
"lib/netstandard1.1/xunit.core.dll": {}
}
},
"xunit.extensibility.execution/2.3.1": {
"dependencies": {
"xunit.extensibility.core": "2.3.1"
},
"runtime": {
"lib/netstandard1.1/xunit.execution.dotnet.dll": {}
}
}
}
},
"libraries": {
"EcommerceStore/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"xunit/2.3.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-IWux0xXfZ/bC7SgooK5rmW5KwCwFg9GFslmPxA7+pJsT+2SRyhOfOgNUXDd7B09UN4f6kogRT2TqNi6gbWEspA==",
"path": "xunit/2.3.1",
"hashPath": "xunit.2.3.1.nupkg.sha512"
},
"xunit.abstractions/2.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-bDm/zdG5rnRDsobKuKwrvL4HccBdC0uvT12be6fG12P3d1U7u9Wkvfoq/PM2GeyIeb0Dtcmm/7k2oaawiqQ2Dg==",
"path": "xunit.abstractions/2.0.1",
"hashPath": "xunit.abstractions.2.0.1.nupkg.sha512"
},
"xunit.analyzers/0.7.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-pEjPJ/pd+r9blGBJ9bXg961phkAiCl4k2DwxwWGEZyYC/7Tb1xJ1az0H18uGANX7zFIkvE5ZO1eZZ4vU7gny7w==",
"path": "xunit.analyzers/0.7.0",
"hashPath": "xunit.analyzers.0.7.0.nupkg.sha512"
},
"xunit.assert/2.3.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-+mUMp3aJOS0ag3qJ2tUhVa930KhwjyypxXT4Ab8lQozEQN8/xgkblQnYs0woIWpr2NbzEOxsZojytl9NBVRKxg==",
"path": "xunit.assert/2.3.1",
"hashPath": "xunit.assert.2.3.1.nupkg.sha512"
},
"xunit.core/2.3.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-LOG4qOFuVQcjYcIuZbKeo03Uvng3lSb2gZJU9ANljwCf+PTd//iAMZS5qcJQZrjhndc4aOUlJGQy5wa0+/iZ6w==",
"path": "xunit.core/2.3.1",
"hashPath": "xunit.core.2.3.1.nupkg.sha512"
},
"xunit.extensibility.core/2.3.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-1mgYqXeQfU+7zcSRW8/5Uf1jVZ5+5WELmi+BuRTh0xu/x0Q0gK0SuR3FLUF4BSd8sfZzvrRUrhWj3ltpyFxhrg==",
"path": "xunit.extensibility.core/2.3.1",
"hashPath": "xunit.extensibility.core.2.3.1.nupkg.sha512"
},
"xunit.extensibility.execution/2.3.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-i8xrHfKC5dyBWQ7I15FePzm0m8KNToBsTleCCQbOQuXRPZIvupd4nnfaCPeJuKHHe7yJ8JGtWxjIgw0ow/cMhg==",
"path": "xunit.extensibility.execution/2.3.1",
"hashPath": "xunit.extensibility.execution.2.3.1.nupkg.sha512"
}
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\Luay\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\Luay\\.nuget\\packages",
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackagesFallback",
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "netcoreapp2.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "2.0.0"
}
}
}
Loading