-
Notifications
You must be signed in to change notification settings - Fork 7
Homework #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Homework #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,13 +19,19 @@ public CoffeeService() | |
| public void AddCoffee(CoffeeModel coffeeToAdd) | ||
| { | ||
| if (coffeeToAdd == null) throw new Exception("You should not add null entries!"); | ||
|
|
||
| coffeeModels.Add(coffeeToAdd); | ||
|
|
||
| if (coffeeModels.Any(i => i == coffeeToAdd)) throw new Exception("Already exists an entry with the same Id"); | ||
| if (!(coffeeToAdd.Id == Guid.Empty || coffeeToAdd.Name == null || coffeeToAdd.Price <= 0.0f || coffeeModels.Any(j => j.Name == coffeeToAdd.Name) || coffeeModels.Any(j => j.Id == coffeeToAdd.Id) || coffeeModels.Any(j => j.Price == coffeeToAdd.Price))) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please make a method that does all of these checks. No line of code should be that big in order to scroll to see. |
||
|
|
||
| coffeeModels.Add(coffeeToAdd); | ||
| } | ||
|
|
||
| public void DeleteCoffee(Guid coffeeId) | ||
| { | ||
| throw new NotImplementedException(); | ||
|
|
||
| if(coffeeId == Guid.Empty) throw new Exception("The Id given is empty"); | ||
| if (coffeeModels.Any(j => j.Id == coffeeId)) | ||
| coffeeModels.Remove(coffeeModels.First(i => i.Id == coffeeId)); | ||
cosminboc marked this conversation as resolved.
Show resolved
Hide resolved
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add indentation for the success if branch, it's confusing to have them one right after another |
||
| } | ||
|
|
||
| public List<CoffeeModel> GetCoffees() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,107 @@ public void AddNullCoffee_Throws_NewException() | |
| } | ||
|
|
||
| //TODO: Add Unit test for Remaining add cases | ||
| //Todo: Add Unit test for deleting case | ||
| [Test] | ||
| public void AddCoffeWithoutPrice_DoesNotAddCoffee() | ||
| { | ||
| var CoffeeLenghtList = coffeeService.GetCoffees().Count; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. naming, please use camelCase, not PascalCase |
||
| var AddCoffeeDetails = new CoffeeModel(); | ||
| AddCoffeeDetails.Id = Guid.NewGuid(); | ||
| AddCoffeeDetails.Name = "Your coffe name"; | ||
| coffeeService.AddCoffee(AddCoffeeDetails); | ||
| Assert.AreEqual(CoffeeLenghtList, coffeeService.GetCoffees().Count); | ||
| } | ||
|
|
||
| [Test] | ||
| public void AddCoffeWithoutName_DoesNotAddCoffee() | ||
| { | ||
| var CoffeeLenghtList = coffeeService.GetCoffees().Count; | ||
| var AddCoffeeDetails = new CoffeeModel(); | ||
| AddCoffeeDetails.Id = Guid.NewGuid(); | ||
| AddCoffeeDetails.Price = 10.68f; | ||
| coffeeService.AddCoffee(AddCoffeeDetails); | ||
| Assert.AreEqual(CoffeeLenghtList, coffeeService.GetCoffees().Count); | ||
| } | ||
|
|
||
| [Test] | ||
| public void AddCoffeWithoutId_DoesNotAddCoffee() | ||
| { | ||
| var CoffeeLenghtList = coffeeService.GetCoffees().Count; | ||
| var AddCoffeeDetails = new CoffeeModel(); | ||
| AddCoffeeDetails.Name = "Your coffe name"; | ||
| AddCoffeeDetails.Price = 22.20f; | ||
| coffeeService.AddCoffee(AddCoffeeDetails); | ||
| Assert.AreEqual(CoffeeLenghtList, coffeeService.GetCoffees().Count); | ||
| } | ||
|
|
||
| [Test] | ||
| public void AddCoffee_ExistingCoffee_ThrowsException() | ||
| { | ||
|
|
||
| var AddCoffeeDetails = coffeeService.GetCoffees()[0]; | ||
|
|
||
| var ex = Assert.Throws<Exception>(() => coffeeService.AddCoffee(AddCoffeeDetails)); | ||
| Assert.AreEqual(ex.Message, "Already exists an entry with the same Id"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a space between action and assertion |
||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove white spaces |
||
|
|
||
| } | ||
|
|
||
| [Test] | ||
| public void AddCoffee_ExistingCoffeePrice_DoesNotAddCoffee() | ||
| { | ||
| var CoffeeLenghtList = coffeeService.GetCoffees().Count; | ||
| var AddCoffeeDetails = new CoffeeModel(); | ||
|
|
||
| AddCoffeeDetails.Name = "hipoooo"; | ||
| AddCoffeeDetails.Id = Guid.NewGuid(); | ||
| AddCoffeeDetails.Price = coffeeService.GetCoffees()[0].Price; | ||
|
|
||
| Assert.AreEqual(CoffeeLenghtList, coffeeService.GetCoffees().Count); | ||
| } | ||
|
|
||
| [Test] | ||
| public void AddCoffee_ExistingCoffeeName_DoesNotAddCoffee() | ||
| { | ||
| var CoffeeLenghtList = coffeeService.GetCoffees().Count; | ||
| var AddCoffeeDetails = new CoffeeModel(); | ||
|
|
||
| AddCoffeeDetails.Name = coffeeService.GetCoffees()[0].Name; | ||
| AddCoffeeDetails.Id = Guid.NewGuid(); | ||
| AddCoffeeDetails.Price = 15.58f; | ||
|
|
||
| Assert.AreEqual(CoffeeLenghtList, coffeeService.GetCoffees().Count); | ||
| } | ||
|
|
||
| [Test] | ||
| public void AddCoffee_ExistingCoffeeId_DoesNotAddCoffee() | ||
| { | ||
| var CoffeeLenghtList = coffeeService.GetCoffees().Count; | ||
| var AddCoffeeDetails = new CoffeeModel(); | ||
|
|
||
| AddCoffeeDetails.Name = "malamala"; | ||
| AddCoffeeDetails.Id = coffeeService.GetCoffees()[0].Id; | ||
| AddCoffeeDetails.Price = 15.58f; | ||
|
|
||
| Assert.AreEqual(CoffeeLenghtList, coffeeService.GetCoffees().Count); | ||
| } | ||
|
|
||
| //Todo: Add Unit test for deleting case | ||
| [Test] | ||
| public void DeleteCoffeeWithEmptyId_Throws_NewException() | ||
| { | ||
| var coffeeToDelete = new CoffeeModel(); | ||
| var ex = Assert.Throws<Exception>(() => coffeeService.DeleteCoffee(coffeeToDelete.Id)); | ||
|
|
||
| Assert.AreEqual(ex.Message, "The Id given is empty"); | ||
| } | ||
| [Test] | ||
| public void DeletedCoffee() | ||
| { | ||
| var deletedcoffee = coffeeService.GetCoffees().First(); | ||
|
|
||
| coffeeService.DeleteCoffee(deletedcoffee.Id); | ||
|
|
||
| Assert.IsTrue(deletedcoffee != coffeeService.GetCoffees().First()); | ||
cosminboc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.