Ejemplo n.º 1
0
        public async Task EditAsync_ShouldSuccessfullyEdit()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var driverService          = new DriverService(context);
            var editDriverServiceModel = new EditDriverServiceModel();
            var driverId       = 1;
            var driverFullName = "DFN 3";

            editDriverServiceModel.Id       = driverId;
            editDriverServiceModel.FullName = driverFullName;

            await driverService.EditAsync(editDriverServiceModel);

            var expectedResult = driverFullName;
            var actualResult   = driverService
                                 .All()
                                 .First()
                                 .FullName;

            Assert.True(expectedResult == actualResult);
        }
Ejemplo n.º 2
0
        public async Task EditAsync_WithNonExistingIdShouldThrowArgumentNullException()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var driverService          = new DriverService(context);
            var editDriverServiceModel = new EditDriverServiceModel();

            editDriverServiceModel.Id = 3;

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await driverService.EditAsync(editDriverServiceModel);
            });
        }
Ejemplo n.º 3
0
        public async Task EditAsync_WithOverMaxNameLengthShouldThrowInvalidOperationException()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var driverService          = new DriverService(context);
            var editDriverServiceModel = new EditDriverServiceModel();
            var driverFullName         = "qwertyuiop qwertyuiop qwertyuiop qwertyuiop qwertyuiop";

            editDriverServiceModel.FullName = driverFullName;
            editDriverServiceModel.Id       = 1;
            var message = "Driver's fullname cannot be more than 50 characters.";

            var exception = await Assert.ThrowsAsync <InvalidOperationException>(async() =>
            {
                await driverService.EditAsync(editDriverServiceModel);
            });

            Assert.Equal(message, exception.Message);
        }
Ejemplo n.º 4
0
        public async Task EditAsync_WithExistingNameShouldThrowInvalidOperationException()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var driverService          = new DriverService(context);
            var editDriverServiceModel = new EditDriverServiceModel();
            var driverFullName         = "DFN 2";

            editDriverServiceModel.FullName = driverFullName;
            editDriverServiceModel.Id       = 1;
            var message = "Driver's fullname already exists.";

            var exception = await Assert.ThrowsAsync <InvalidOperationException>(async() =>
            {
                await driverService.EditAsync(editDriverServiceModel);
            });

            Assert.Equal(message, exception.Message);
        }