示例#1
0
        public async Task CreateLocationAsync_PassedValidObject_ReturnsObject()
        {
            //Arrange
            var oldLocation = new Location()
            {
                ReservationId = 1
            };
            var locationDto = new LocationCreateDto()
            {
                ReservationId = 1
            };

            mockLocationRepository
            .Setup(p => p
                   .GetActualLocationByReservationIdAsync(oldLocation.ReservationId))
            .ReturnsAsync(oldLocation);
            mockLocationRepository
            .Setup(s => s.SaveChangesAsync())
            .Verifiable();
            var service = new LocationService(mockLocationRepository.Object, mapper);
            //Act
            var newLocation = await service.CreateLocationAsync(locationDto);

            //Assert
            Assert.Equal(newLocation.ReservationId, locationDto.ReservationId);
            Assert.Equal(newLocation.LocationId, oldLocation.LocationId);
            Assert.True(newLocation.IsActual);
            Assert.False(oldLocation.IsActual);
            Assert.IsType <LocationDto>(newLocation);
        }
        public void CreateLocation_Test(string name, Country country)
        {
            //Arrange
            var fixture = new Fixture();

            var location        = Fixtures.LocationFixture(name, country);
            var mapper          = Mapper.GetAutoMapper();
            var locationRepoMoq = LocationMoqs.LocationRepositoryMoq(mapper.Map <LocationEntity>(location));
            var locationSvc     = new LocationService(mapper, locationRepoMoq.Object);

            //Act
            var newLocation = locationSvc.CreateLocationAsync(location).Result;

            //Assert
            var actual   = JsonConvert.SerializeObject(location);
            var expected = JsonConvert.SerializeObject(newLocation);

            Assert.Equal(expected.Trim(), actual.Trim());
        }