public async Task WithSignInUserAndWithoutScheduleTestDrive_ShouldReturnModelWithNullTestDriveId() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var models = await this.CallGetCarsInventoryViewModelAsync(dbContext, true, dbUser.Id); Assert.True(models.All(m => m.TestDriveId == null)); }
public async Task WithoutSignInUserAndCar_ShouldReturnModelWithFalseIsTestDriveScheduled() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var models = await this.CallGetCarsInventoryViewModelAsync(dbContext, true, dbUser.Id); Assert.True(models.All(m => m.IsTestDriveScheduled == false)); }
public async Task WithSignInUserAndScheduleTestDrive_ShouldReturnModelWithTrueIsTestDriveScheduled() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var dbTestDrive = this.ScheduleTestDrive(dbContext, dbUser.Id); var models = await this.CallGetCarsInventoryViewModelAsync(dbContext, true, dbUser.Id); Assert.Contains(models, m => m.IsTestDriveScheduled); }
public async void WithIncorrectId_ShouldThrowExcception() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var service = this.GetService(dbContext, dbUser.Id); var user = new Mock <ClaimsPrincipal>().Object; var incorrectId = Guid.NewGuid().ToString(); await Assert.ThrowsAnyAsync <Exception>(async() => await service.GetByIdAsync(incorrectId, user)); }
public async void WithTestDriveOnAnotherUser_ShouldThrowException() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var dbUpcomingStatus = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming); var dbTestDrive = SeedTestDrivesMethods.SeedTestDriveWithCar <NewCar>(dbContext, "", dbUpcomingStatus); var service = this.GetService(dbContext, dbUser.Id); var user = new Mock <ClaimsPrincipal>().Object; await Assert.ThrowsAnyAsync <Exception>(async() => await service.GetByIdAsync(dbTestDrive.Id, user)); }
public void WithoutTestDrives_ShouldReturnEmptyCollection() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var user = new Mock <ClaimsPrincipal>().Object; var service = this.GetService(dbContext, dbUser.Id); var models = service.GetAll(user); Assert.Empty(models); }
public async void WithModel_ShouldScheduleTestDriveWithUpcomingStatus() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var dbCar = SeedCarsMethods.SeedCar <NewCar>(dbContext); var model = this.GetModel(dbCar.Id); await this.CallScheduleTestDriveAsync(model, dbContext, dbUser.Id); Assert.Equal(TestDriveStatus.Upcoming.ToString(), dbContext.TestDrives.First().Status.Name); }
public async void WithUpcomingTestDrive_ShouldCancelTestDrive() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var dbUpcomingStatus = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming); var dbTestDrive = SeedTestDrivesMethods.SeedTestDriveWithCar <NewCar>(dbContext, dbUser.Id, dbUpcomingStatus); await this.CallCancelTestDriveAsync(dbContext, dbTestDrive.Id, dbUser.Id); Assert.Equal(TestDriveStatus.Canceled.ToString(), dbTestDrive.Status.Name); }
public async void WithSignInUserWithTestDrive_ShouldReturnIsTestDriveScheduledTrue() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var dbStatus = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming); var dbCar = SeedCarsMethods.SeedCarWithTestDrive <NewCar>(dbContext, dbUser.Id, dbStatus); var model = await this.CallGetCarViewModelAsync(dbContext, dbCar.Id, true, dbUser.Id); Assert.True(model.IsTestDriveScheduled); }
public async void WithAdminAndUser_ShouldReturnModelWithCorrectTotalUsersCount() { var dbContext = this.GetDbContext(); var service = this.GetService(dbContext); SeedUsersMethods.SeedUser(dbContext, this.AdminRole); SeedUsersMethods.SeedUser(dbContext, this.UserRole); var model = await service.GetStatisticsAsync(); Assert.Equal(1, model.TotalUsersCount); }
public async void WithModelWithIncorrectCarId_ShouldThrowException() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var carIncorrectId = Guid.NewGuid().ToString(); var model = this.GetModel(carIncorrectId); var exception = await Assert.ThrowsAnyAsync <ArgumentException>(async() => await this.CallScheduleTestDriveAsync(model, dbContext, dbUser.Id)); Assert.Equal(ErrorConstants.IncorrectId, exception.Message); }
public async void WithSignInUserWithTestDrive_ShouldReturnCorrectTestDriveId() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var dbStatus = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming); var dbCar = SeedCarsMethods.SeedCarWithTestDrive <NewCar>(dbContext, dbUser.Id, dbStatus); var model = await this.CallGetCarViewModelAsync(dbContext, dbCar.Id, true, dbUser.Id); Assert.Equal(dbCar.TestDrives.First().Id, model.TestDriveId); }
public async void WithIncorrectTestDriveId_ShouldThrowException() { var dbContext = this.GetDbContext(); var incorrectTestDriveId = Guid.NewGuid().ToString(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var dbUpcomingStatus = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming); var exception = await Assert.ThrowsAsync <ArgumentException>(async() => await this.CallCancelTestDriveAsync(dbContext, incorrectTestDriveId, dbUpcomingStatus.Id)); Assert.Equal(ErrorConstants.IncorrectId, exception.Message); }
public async void WithIncorrectCarId_ShouldThrowException() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var incorrectCarId = Guid.NewGuid().ToString(); var exception = await Assert .ThrowsAsync <ArgumentException>(async() => await this.CallGetCarViewModelAsync(dbContext, incorrectCarId, false, null)); Assert.Equal(ErrorConstants.IncorrectId, exception.Message); }
public async void WithCanceledTestDrive_ShouldThrowExcpetion() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming); var dbTestDrive = SeedTestDrivesMethods.SeedTestDriveWithCar <NewCar>(dbContext, dbUser.Id, this.CanceledStatus); var exception = await Assert.ThrowsAsync <ArgumentException>(async() => await this.CallCancelTestDriveAsync(dbContext, dbTestDrive.Id, dbUser.Id)); Assert.Equal(ErrorConstants.UpcomingStatusRequired, exception.Message); }
public async void WithCorrectId_ShouldReturnTestDrive() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var dbUpcomingStatus = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming); var dbTestDrive = SeedTestDrivesMethods.SeedTestDriveWithCar <NewCar>(dbContext, dbUser.Id, dbUpcomingStatus); var service = this.GetService(dbContext, dbUser.Id); var user = new Mock <ClaimsPrincipal>().Object; var model = await service.GetByIdAsync(dbTestDrive.Id, user); Assert.Equal(dbTestDrive.Id, model.Id); }
public async void WithScheduledTestDriveFromAnother_ShouldSheduleTestDrive() { var dbContext = this.GetDbContext(); this.SheduleTestDrive(dbContext); var dbUser = SeedUsersMethods.SeedUser(dbContext); var dbCar = SeedCarsMethods.SeedCar <NewCar>(dbContext); var model = this.GetModel(dbCar.Id); await this.CallScheduleTestDriveAsync(model, dbContext, dbUser.Id); Assert.Equal(2, dbContext.TestDrives.Count()); }
public async void WithUpcomingTestDriveFromAnotherUser_ShouldThrowExcpetion() { var dbContext = this.GetDbContext(); var notSignInUser = SeedUsersMethods.SeedUser(dbContext); var signInUser = SeedUsersMethods.SeedUser(dbContext); var dbUpcomingStatus = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming); var dbTestDrive = SeedTestDrivesMethods.SeedTestDriveWithCar <NewCar>(dbContext, notSignInUser.Id, dbUpcomingStatus); var exception = await Assert.ThrowsAsync <ArgumentException>(async() => await this.CallCancelTestDriveAsync(dbContext, dbTestDrive.Id, signInUser.Id)); Assert.Equal(ErrorConstants.IncorrectId, exception.Message); }
public async void WithSignInUser_ShouldReturnCorrectIsTestDriveScheduledForTheCurrentUser() { var dbContext = this.GetDbContext(); var dbSignInUser = SeedUsersMethods.SeedUser(dbContext); var dbNotSignInUser = SeedUsersMethods.SeedUser(dbContext); var dbCar = SeedCarsMethods.SeedCarWithEverything <NewCar>(dbContext); SeedTestDrivesMethods.SeedUpcomingTestDrive(dbContext, dbCar, dbNotSignInUser.Id); var model = await this.CallGetCarViewModelAsync(dbContext, dbCar.Id, true, dbSignInUser.Id); Assert.False(model.IsTestDriveScheduled); }
public async void WithUsersWithTestDrivesWithTheSameCar_ShouldReturnCorrectTestDriveIdForTheCurrentUser() { var dbContext = this.GetDbContext(); var dbSignInUser = SeedUsersMethods.SeedUser(dbContext); var dbNotSignInUser = SeedUsersMethods.SeedUser(dbContext); var dbCar = SeedCarsMethods.SeedCarWithEverything <NewCar>(dbContext); var dbSignInUserTestDrive = SeedTestDrivesMethods.SeedUpcomingTestDrive(dbContext, dbCar, dbSignInUser.Id); var dbNotSignInUserTestDrive = SeedTestDrivesMethods.SeedUpcomingTestDrive(dbContext, dbCar, dbNotSignInUser.Id); var model = await this.CallGetCarViewModelAsync(dbContext, dbCar.Id, true, dbSignInUser.Id); Assert.Equal(dbSignInUserTestDrive.Id, model.TestDriveId); }
public async void WithAlreadyExistingEmail_ShouldNotCreateNewUser() { var dbContext = this.GetDbContext(); var mockedUserManager = CommonGetMockMethods.GetUserManager(); var dbUser = SeedUsersMethods.SeedUser(dbContext, Guid.NewGuid().ToString()); var service = this.GetService(dbContext, mockedUserManager.Object); var dbRole = SeedRolesMethods.SeedAdminRole(dbContext); var serviceModel = new UserServiceModel(); serviceModel.Email = dbUser.Email; await service.SeedUserAsync(serviceModel, "", dbRole.Name); mockedUserManager.Verify(um => um.CreateAsync(It.IsAny <User>(), It.IsAny <string>()), Times.Never); }
public void WithTestDrives_ShouldReturnOnlyUserTestDrives() { var dbContext = this.GetDbContext(); var dbUser = SeedUsersMethods.SeedUser(dbContext); var upcomingStatus = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming); SeedCarsMethods.SeedCarWithTestDrive <NewCar>(dbContext, dbUser.Id, upcomingStatus); SeedCarsMethods.SeedCarWithTestDrive <NewCar>(dbContext, "", upcomingStatus); var user = new Mock <ClaimsPrincipal>().Object; var service = this.GetService(dbContext, dbUser.Id); var models = service.GetAll(user); Assert.Equal(dbUser.TestDrives.First().Id, models.First().Id); Assert.Single(models); }