public void CreateValidLodgingTestOk() { var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict); lodgingRepositoryMock.Setup(m => m.Add(It.IsAny <Lodging>())); lodgingRepositoryMock.Setup(m => m.GetLodgingByNameAndTouristSpot(lodging.Name, touristSpot.Id)).Returns(value: null); var touristSpotRepositoryMock = new Mock <ITouristSpotRepository>(MockBehavior.Strict); touristSpotRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(touristSpot); TouristSpotManagement touristSpotLogic = new TouristSpotManagement(touristSpotRepositoryMock.Object); LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object, touristSpotLogic); Lodging resultOfCreateALodging = lodgingLogic.Create(lodging, touristSpot.Id, listOfPicturesPath); Lodging lodgingToCompare = new Lodging() { Id = resultOfCreateALodging.Id, Name = resultOfCreateALodging.Name, QuantityOfStars = resultOfCreateALodging.QuantityOfStars, Address = resultOfCreateALodging.Address, Images = resultOfCreateALodging.Images, PricePerNight = resultOfCreateALodging.PricePerNight, IsAvailable = resultOfCreateALodging.IsAvailable, TouristSpot = resultOfCreateALodging.TouristSpot }; lodgingRepositoryMock.VerifyAll(); Assert.AreEqual(lodging, lodgingToCompare); }
public void CreateInvalidLodgingInternalErrorWhenSearchLodgingByNameTest() { var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict); lodgingRepositoryMock.Setup(m => m.Add(It.IsAny <Lodging>())); lodgingRepositoryMock.Setup(m => m.GetLodgingByNameAndTouristSpot(lodging.Name, touristSpot.Id)).Throws(new ServerException()); var touristSpotRepositoryMock = new Mock <ITouristSpotRepository>(MockBehavior.Strict); touristSpotRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Throws(new ClientBusinessLogicException()); TouristSpotManagement touristSpotLogic = new TouristSpotManagement(touristSpotRepositoryMock.Object); LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object, touristSpotLogic); Lodging resultOfCreateALodging = lodgingLogic.Create(lodging, touristSpot.Id, listOfPicturesPath); }
public void CreateInvalidLodgingWithInvalidPriceTest() { lodging.PricePerNight = -10; var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict); lodgingRepositoryMock.Setup(m => m.Add(It.IsAny <Lodging>())); lodgingRepositoryMock.Setup(m => m.GetLodgingByNameAndTouristSpot(lodging.Name, touristSpot.Id)).Returns(value: null); var touristSpotRepositoryMock = new Mock <ITouristSpotRepository>(MockBehavior.Strict); touristSpotRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(touristSpot); TouristSpotManagement touristSpotLogic = new TouristSpotManagement(touristSpotRepositoryMock.Object); LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object, touristSpotLogic); Lodging resultOfCreateALodging = lodgingLogic.Create(lodging, touristSpot.Id, listOfPicturesPath); }