Beispiel #1
0
        public async Task EditAsync_ShouldSuccessfullyEdit()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var roadObjectService          = new RoadObjectService(context);
            var editRoadObjectServiceModel = new EditRoadObjectServiceModel();
            var roadObjectId   = 1;
            var roadObjectName = "FN 3";

            editRoadObjectServiceModel.Id   = roadObjectId;
            editRoadObjectServiceModel.Name = roadObjectName;

            await roadObjectService.EditAsync(editRoadObjectServiceModel);

            var expectedResult = roadObjectName;
            var actualResult   = roadObjectService
                                 .All()
                                 .First()
                                 .Name;

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

            await this.SeedDataAsync(context);

            var roadObjectService          = new RoadObjectService(context);
            var editRoadObjectServiceModel = new EditRoadObjectServiceModel();

            editRoadObjectServiceModel.Id = 3;

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await roadObjectService.EditAsync(editRoadObjectServiceModel);
            });
        }
Beispiel #3
0
        public async Task EditAsync_WithOverMaxNameLengthShouldThrowInvalidOperationException()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var roadObjectService          = new RoadObjectService(context);
            var editRoadObjectServiceModel = new EditRoadObjectServiceModel();
            var roadObjectName             = "qwertyuiop qwertyuiop qwertyuiop qwertyuiop qwertyuiop";

            editRoadObjectServiceModel.Name = roadObjectName;
            editRoadObjectServiceModel.Id   = 1;
            var message = "Road object's name cannot be more than 50 characters.";

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

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

            await this.SeedDataAsync(context);

            var roadObjectService          = new RoadObjectService(context);
            var editRoadObjectServiceModel = new EditRoadObjectServiceModel();
            var roadObjectName             = "RON 2";

            editRoadObjectServiceModel.Name = roadObjectName;
            editRoadObjectServiceModel.Id   = 1;
            var message = "Road object's name already exists.";

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

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