public async Task CreateAsync_ValidData_Successful() { // Arrange. Seed(TripFlipDbContext, ValidUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, TripRoleEntitiesToSeed); Seed(TripFlipDbContext, TripSubscriberRoleEntitiesToSeed); CurrentUserService = CreateCurrentUserService(ValidUser.Id, ValidUser.Email); var createRouteDto = GetCreateRouteDto(); var routeService = new RouteService(TripFlipDbContext, Mapper, CurrentUserService); var routeDtoComparer = new RouteDtoComparer(); var expectedRouteDto = new RouteDto() { Id = 1, Title = createRouteDto.Title, TripId = createRouteDto.TripId }; // Act. var resultItemDto = await routeService.CreateAsync(createRouteDto); // Assert. Assert.AreEqual(0, routeDtoComparer.Compare(expectedRouteDto, resultItemDto)); }
public async Task CreateAsync_NonExistentTripId_ExceptionThrown() { // Arrange. var nonExistentTripId = 1; var createRouteDto = GetCreateRouteDto(tripId: nonExistentTripId); var routeService = new RouteService(TripFlipDbContext, Mapper, CurrentUserService); // Act + Assert. await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await routeService.CreateAsync(createRouteDto)); }
public async Task CreateAsync_CurrentUserNotTripAdmin_ExceptionThrown() { // Arrange. Seed(TripFlipDbContext, ValidUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); CurrentUserService = CreateCurrentUserService(ValidUser.Id, ValidUser.Email); var createRouteDto = GetCreateRouteDto(); var routeService = new RouteService(TripFlipDbContext, Mapper, CurrentUserService); // Act + Assert. await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await routeService.CreateAsync(createRouteDto)); }
public async Task CreateAsync_InvalidCurrentUser_ExceptionThrown( string displayName, ICurrentUserService currentUserService) { Seed(TripFlipDbContext, NonExistentUser); Seed(TripFlipDbContext, NotTripSubscriberUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); CurrentUserService = currentUserService; var createRouteDto = GetCreateRouteDto(); var routeService = new RouteService(TripFlipDbContext, Mapper, CurrentUserService); // Act + Assert. await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await routeService.CreateAsync(createRouteDto), displayName); }