Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Copy link
Owner

Choose a reason for hiding this comment

The 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));
Copy link
Owner

Choose a reason for hiding this comment

The 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The 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");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a space between action and assertion


Copy link
Owner

Choose a reason for hiding this comment

The 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());
}
}
}