Пример #1
0
        public async Task CreateAsync_WithEmptyNameShouldThrowArgumentNullException()
        {
            MapperInitializer.InitializeMapper();
            var context                      = ApplicationDbContextInMemoryFactory.InitializeContext();
            var roadObjectService            = new RoadObjectService(context);
            var createRoadObjectServiceModel = new CreateRoadObjectServiceModel();
            var roadObjectName               = "  ";

            createRoadObjectServiceModel.Name = roadObjectName;

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await roadObjectService.CreateAsync(createRoadObjectServiceModel);
            });
        }
Пример #2
0
        public async Task CreateAsync_WithOverMaxNameLengthShouldThrowInvalidOperationException()
        {
            MapperInitializer.InitializeMapper();
            var context                      = ApplicationDbContextInMemoryFactory.InitializeContext();
            var roadObjectService            = new RoadObjectService(context);
            var createRoadObjectServiceModel = new CreateRoadObjectServiceModel();
            var roadObjectName               = "qwertyuiop qwertyuiop qwertyuiop qwertyuiop qwertyuiop";

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

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

            Assert.Equal(message, exception.Message);
        }
Пример #3
0
        public async Task CreateAsync_ShouldSuccessfullyCreate()
        {
            MapperInitializer.InitializeMapper();
            var context                      = ApplicationDbContextInMemoryFactory.InitializeContext();
            var roadObjectService            = new RoadObjectService(context);
            var createRoadObjectServiceModel = new CreateRoadObjectServiceModel();
            var roadObjectName               = "RON 1";

            createRoadObjectServiceModel.Name = roadObjectName;

            await roadObjectService.CreateAsync(createRoadObjectServiceModel);

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

            Assert.True(expectedResult == actualResult);
        }
Пример #4
0
        public async Task CreateAsync_WithExistingNameShouldThrowInvalidOperationException()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var roadObjectService            = new RoadObjectService(context);
            var createRoadObjectServiceModel = new CreateRoadObjectServiceModel();
            var roadObjectName = "RON 1";

            createRoadObjectServiceModel.Name = roadObjectName;
            var message = "Road object's name already exists.";

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

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