public void TestAirConditioner_WithoutAlreadyExistingReport_ShouldThrowCorrectDuplicateEntryException() { Mock <IAirConditioner> fakeAC = new Mock <IAirConditioner>(); fakeAC.Setup(x => x.Test()).Returns(true); Mock <IAirConditionerTesterDatabase> databaseMock = new Mock <IAirConditionerTesterDatabase>(); Mock <IRepository <IAirConditioner> > fakeACrepository = new Mock <IRepository <IAirConditioner> >(); Mock <IReportsRepository> fakeReportsRepository = new Mock <IReportsRepository>(); databaseMock.Setup(x => x.AirConditioners).Returns(fakeACrepository.Object); databaseMock.Setup(x => x.Reports).Returns(fakeReportsRepository.Object); fakeACrepository.Setup(x => x.GetItem(It.IsAny <string>(), It.IsAny <string>())).Returns(fakeAC.Object); fakeReportsRepository.Setup(x => x.Add(It.IsAny <IReport>())) .Throws(new DuplicateEntryException(Constants.DuplicateEntry)); IAirConditionerTesterDatabase fakeDatabase = databaseMock.Object; var controller = new AirConditionerTesterSystem(fakeDatabase); controller.TestAirConditioner("Toshiba", "EX100"); try { controller.TestAirConditioner("Toshiba", "EX100"); } catch (DuplicateEntryException ex) { Assert.AreEqual(string.Format(Constants.DuplicateEntry), ex.Message, "Expected message did not match!"); throw new DuplicateEntryException(Constants.DuplicateEntry); } }
public void TestAirConditioner_WithCorrectInput_ShouldAddCorrectReport() { Mock <IAirConditioner> fakeAC = new Mock <IAirConditioner>(); fakeAC.Setup(x => x.Manufacturer).Returns("Toshiba"); fakeAC.Setup(x => x.Model).Returns("EX200"); fakeAC.Setup(x => x.Test()).Returns(false); Mock <IAirConditionerTesterDatabase> databaseMock = new Mock <IAirConditionerTesterDatabase>(); Mock <IRepository <IAirConditioner> > fakeACrepository = new Mock <IRepository <IAirConditioner> >(); Mock <IReportsRepository> fakeReportsRepository = new Mock <IReportsRepository>(); databaseMock.Setup(x => x.AirConditioners).Returns(fakeACrepository.Object); databaseMock.Setup(x => x.Reports).Returns(fakeReportsRepository.Object); fakeACrepository.Setup(x => x.GetItem(It.IsAny <string>(), It.IsAny <string>())).Returns(fakeAC.Object); IReport report = null; fakeReportsRepository.Setup(x => x.Add(It.IsAny <IReport>())).Callback <IReport>(r => report = r); IAirConditionerTesterDatabase fakeDatabase = databaseMock.Object; var controller = new AirConditionerTesterSystem(fakeDatabase); controller.TestAirConditioner("Toshiba", "EX200"); Assert.AreEqual("Toshiba", report.Manufacturer, "Manufacturer did not match!"); Assert.AreEqual("EX200", report.Model, "Model did not match!"); Assert.AreEqual(Mark.Failed, report.Mark, "Mark did not match!"); }
public void TestAirConditioner_WithCorrectInput_ShouldCallAirConditionerTestMethod() { Mock <IAirConditioner> fakeAC = new Mock <IAirConditioner>(); Mock <IAirConditionerTesterDatabase> databaseMock = new Mock <IAirConditionerTesterDatabase>(); Mock <IRepository <IAirConditioner> > fakeACrepository = new Mock <IRepository <IAirConditioner> >(); Mock <IReportsRepository> fakeReportsRepository = new Mock <IReportsRepository>(); databaseMock.Setup(x => x.AirConditioners).Returns(fakeACrepository.Object); databaseMock.Setup(x => x.Reports).Returns(fakeReportsRepository.Object); fakeACrepository.Setup(x => x.GetItem(It.IsAny <string>(), It.IsAny <string>())).Returns(fakeAC.Object); IAirConditionerTesterDatabase fakeDatabase = databaseMock.Object; var controller = new AirConditionerTesterSystem(fakeDatabase); controller.TestAirConditioner("Toshiba", "EX100"); fakeAC.Verify(x => x.Test(), Times.Exactly(1)); }
public void TestAirConditioner_WithoutExistingEntry_ShouldThrowCorrectNonExistantEntryException() { Mock <IAirConditionerTesterDatabase> databaseMock = new Mock <IAirConditionerTesterDatabase>(); Mock <IRepository <IAirConditioner> > fakeACrepository = new Mock <IRepository <IAirConditioner> >(); databaseMock.Setup(x => x.AirConditioners).Returns(fakeACrepository.Object); fakeACrepository.Setup(x => x.GetItem(It.IsAny <string>(), It.IsAny <string>())).Throws(new NonExistantEntryException(Constants.NonExistantEntry)); IAirConditionerTesterDatabase fakeDatabase = databaseMock.Object; var controller = new AirConditionerTesterSystem(fakeDatabase); try { controller.TestAirConditioner("Toshiba", "EX100"); } catch (NonExistantEntryException ex) { Assert.AreEqual(Constants.NonExistantEntry, ex.Message, "Expected message did not match!"); throw new NonExistantEntryException(""); } }
public void TestAirConditioner_WithCorrectInput_ShouldReturnSuccessMessage() { Mock <IAirConditioner> fakeAC = new Mock <IAirConditioner>(); fakeAC.Setup(x => x.Manufacturer).Returns("Toshiba"); fakeAC.Setup(x => x.Model).Returns("EX200"); fakeAC.Setup(x => x.Test()).Returns(false); Mock <IAirConditionerTesterDatabase> databaseMock = new Mock <IAirConditionerTesterDatabase>(); Mock <IRepository <IAirConditioner> > fakeACrepository = new Mock <IRepository <IAirConditioner> >(); Mock <ReportsRepository> fakeReportsRepository = new Mock <ReportsRepository>(); databaseMock.Setup(x => x.AirConditioners).Returns(fakeACrepository.Object); databaseMock.Setup(x => x.Reports).Returns(fakeReportsRepository.Object); fakeACrepository.Setup(x => x.GetItem(It.IsAny <string>(), It.IsAny <string>())).Returns(fakeAC.Object); IAirConditionerTesterDatabase fakeDatabase = databaseMock.Object; var controller = new AirConditionerTesterSystem(fakeDatabase); var result = controller.TestAirConditioner("Toshiba", "EX200"); Assert.AreEqual("Air Conditioner model EX200 from Toshiba tested successfully.", result, "Expected messages did not match!"); }
public AirConditionerTesterSystem(IAirConditionerTesterDatabase database) { this.Database = database; }
public AirConditionerTesterSystem(IAirConditionerTesterDatabase database) { this.Database = database; }