Пример #1
0
        public async Task EditAsync_ShouldWorkCorrectly()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var seeder  = new OrganizedtripsServiceTestsSeeder();
            await seeder.SeedTripAsync(context);

            var tripRepository = new EfDeletableEntityRepository <OrganizedTrip>(context);

            var service = new OrganizedTripsService(tripRepository);
            var trip    = tripRepository.All().First();
            var model   = new OrganizedTripViewModel
            {
                Id                = trip.Id,
                Name              = trip.Name,
                ImageUrl          = trip.ImageUrl,
                Description       = trip.Description,
                DepartureDateTime = trip.DepartureDateTime,
                ReturnDateTime    = trip.ReturnDateTime,
                DestinationId     = trip.DestinationId,
                PricePerPerson    = trip.PricePerPerson,
                HotelId           = trip.HotelId,
                AvailableSeats    = trip.AvailableSeats,
                Transport         = trip.Transport,
                ReservationType   = trip.ReservationType,
            };

            model.Name              = "EditedTripName";
            model.ImageUrl          = "EditedImageUrl";
            model.PricePerPerson    = 50;
            model.ReservationType   = ReservationType.OrganizedTrip;
            model.Description       = "EditedDescription";
            model.DepartureDateTime = new DateTime(2020, 03, 03, 13, 00, 00);
            model.ReturnDateTime    = new DateTime(2020, 03, 03, 13, 30, 00);
            model.DestinationId     = 1;
            model.HotelId           = 1;
            model.AvailableSeats    = 2;
            model.Transport         = TransportType.Bus;

            // Act
            await service.EditAsync(model.Id, model);

            var actualResult   = tripRepository.All().First();
            var expectedResult = model;

            // Assert
            Assert.True(expectedResult.Name == actualResult.Name);
            Assert.True(expectedResult.ImageUrl == actualResult.ImageUrl);
            Assert.True(expectedResult.Description == actualResult.Description);
            Assert.True(expectedResult.ReservationType == actualResult.ReservationType);
            Assert.True(expectedResult.PricePerPerson == actualResult.PricePerPerson);
            Assert.True(expectedResult.DepartureDateTime == actualResult.DepartureDateTime);
            Assert.True(expectedResult.ReturnDateTime == actualResult.ReturnDateTime);
            Assert.True(expectedResult.AvailableSeats == actualResult.AvailableSeats);
            Assert.True(expectedResult.HotelId == actualResult.HotelId);
            Assert.True(expectedResult.Transport == actualResult.Transport);
            Assert.True(expectedResult.DestinationId == actualResult.DestinationId);
        }
Пример #2
0
        public async Task IsExistingMethod_ShouldReturnFalseIfFlightNotExists()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var seeder  = new OrganizedtripsServiceTestsSeeder();
            await seeder.SeedTripAsync(context);

            var tripRepository = new EfDeletableEntityRepository <OrganizedTrip>(context);

            var service = new OrganizedTripsService(tripRepository);

            // Act
            var actualResult   = service.Exists("TripId");
            var expectedResult = false;

            // Assert
            Assert.True(actualResult == expectedResult);
        }
Пример #3
0
        public async Task DeleteAsync_ShouldSuccessfullyDelete()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var seeder  = new OrganizedtripsServiceTestsSeeder();
            await seeder.SeedTripAsync(context);

            var tripRepository = new EfDeletableEntityRepository <OrganizedTrip>(context);

            var service = new OrganizedTripsService(tripRepository);
            var tripId  = tripRepository.All().First().Id;

            // Act
            var tripsCount = tripRepository.All().Count();
            await service.DeleteAsync(tripId);

            var actualResult   = tripRepository.All().Count();
            var expectedResult = tripsCount - 1;

            // Assert
            Assert.True(actualResult == expectedResult);
        }