private TestDrive SheduleTestDrive(ApplicationDbContext dbContext, string userId = "")
        {
            var dbStatus    = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming);
            var dbTestDrive = SeedTestDrivesMethods.SeedTestDriveWithCar <NewCar>(dbContext, userId, dbStatus);

            return(dbTestDrive);
        }
        public async void WithTestDrivesAndCarAndNotSignInUser_ShouldReturnIsTestDriveScheduledFalse()
        {
            var dbContext = this.GetDbContext();
            var dbStatus  = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming);
            var dbCar     = SeedCarsMethods.SeedCarWithTestDrive <NewCar>(dbContext, "", dbStatus);

            var model = await this.CallGetCarViewModelAsync(dbContext, dbCar.Id, false, null);

            Assert.False(model.IsTestDriveScheduled);
        }
        private ITestDriveService GetService(ApplicationDbContext dbContext, string userId)
        {
            this.CanceledStatus = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Canceled);
            var mockedUserManager = CommonGetMockMethods.GetUserManager();

            CommonSetupMockMethods.SetupMockedUserManagerGetUserId(mockedUserManager, userId);
            var service = this.GetService(dbContext, mockedUserManager.Object);

            return(service);
        }
        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);
        }
예제 #5
0
        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 async void WithAlreadyExistingStatus_ShouldDoNothing()
        {
            var dbContext = this.GetDbContext();
            var dbStatus  = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Canceled);
            var service   = this.GetService(dbContext);

            await service.SeedTestDriveStatusesAsync(dbStatus.Name);

            Assert.Single(dbContext.Statuses);
            Assert.Equal(dbStatus, dbContext.Statuses.First());
        }
        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);
        }
예제 #8
0
        protected IAdminTestDrivesService GetService(ApplicationDbContext dbContext)
        {
            var testDriveRepository = new TestDriveRepository(dbContext);
            var statusRepository    = new StatusRepository(dbContext);

            this.UpcomingStatus = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming);
            this.PassedStatus   = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Passed);
            var adminDeleteService = new AdminCommonDeleteService(dbContext);
            var service            = new AdminTestDrivesService(testDriveRepository, statusRepository, adminDeleteService);

            return(service);
        }
        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);
        }
예제 #11
0
        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 WithStatuses_ShouldAddOnlyNotExistingStatuses()
        {
            var dbContext          = this.GetDbContext();
            var dbStatus           = SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Canceled);
            var upcomingStatusName = TestDriveStatus.Upcoming.ToString();
            var service            = this.GetService(dbContext);

            await service.SeedTestDriveStatusesAsync(dbStatus.Name, upcomingStatusName);

            Assert.Equal(2, dbContext.Statuses.Count());
            Assert.Contains(dbContext.Statuses, s => s.Name == dbStatus.Name);
            Assert.Contains(dbContext.Statuses, s => s.Name == upcomingStatusName);
        }
        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 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);
        }
        private async Task CallScheduleTestDriveAsync(
            ScheduleTestDriveServiceModel model,
            ApplicationDbContext dbContext,
            string userId)
        {
            SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming);
            var mockedUserManager = CommonGetMockMethods.GetUserManager();

            CommonSetupMockMethods.SetupMockedUserManagerGetUserId(mockedUserManager, userId);
            var service = this.GetService(dbContext, mockedUserManager.Object);
            var user    = new Mock <ClaimsPrincipal>().Object;

            await service.ScheduleTestDriveAsync(model, user);
        }
예제 #16
0
        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);
        }