public void CreateValidChairTest() { //Setup Dictionary <int, Chair> chairs = new Dictionary <int, Chair>(); int Id = 1; Mock <IChairRepository> mockChairRepo = new Mock <IChairRepository>(); mockChairRepo.Setup(x => x.AddChair(It.IsAny <Chair>())).Returns <Chair>(arg => InsertIntoDictionaryAndAddId(Id, chairs, arg)); IChairService chairService = new ChairService(mockChairRepo.Object); Chair validChair = new Chair() { Name = "someName", Price = 1 }; //Test Chair chair = chairService.AddChair(validChair); Assert.Single(chairs); // cheks if there as been added ONE chair to the "Repositorie" Assert.NotNull(chair); Assert.Equal(Id, chair.Id); // cheks if the returned chair has the given id Assert.Equal(chairs[Id], chair); }
public void AddChairWithoutNameExpectExeption() { //Setup Mock <IChairRepository> mockChairRepo = new Mock <IChairRepository>(); IChairService chairService = new ChairService(mockChairRepo.Object); //Test var chair = new Chair() { Price = 1 }; Assert.Throws <InvalidDataException>(() => chairService.AddChair(chair)); mockChairRepo.Verify(m => m.AddChair(chair), Times.Never()); }