示例#1
0
        public async Task CreatePublisherAsync_WithRepeatedName_ReturnsFalse()
        {
            // Arrange
            var context        = this.NewInMemoryDatabase();
            var publisherModel = new PublisherCreateServiceModel
            {
                Description = "TestDescription",
                ImageUrl    = "http://www.test.com",
                Name        = "TestName "
            };

            await context.Publishers.AddAsync(
                new Publisher
            {
                Name = "TestName"
            }
                );

            await context.SaveChangesAsync();

            var publishersService = new PublishersService(context);

            // Act
            var result = await publishersService.CreatePublisherAsync(publisherModel);

            // Assert
            Assert.False(result);
            Assert.Equal(1, await context.Publishers.CountAsync());
        }
示例#2
0
        public async Task <bool> CreatePublisherAsync(PublisherCreateServiceModel model)
        {
            if (!this.IsEntityStateValid(model))
            {
                return(false);
            }

            var nameToCheck = model.Name.Trim().ToLower();

            // Check if publisher name has already been taken
            if (await this.Context.Publishers.AnyAsync(p => p.Name.ToLower() == nameToCheck))
            {
                return(false);
            }

            model.Name = model.Name.Trim();

            var dbPublisher = Mapper.Map <Publisher>(model);

            await this.Context.Publishers.AddAsync(dbPublisher);

            await this.Context.SaveChangesAsync();

            return(true);
        }
示例#3
0
        public async Task CreatePublisherAsync_WithIncorrectModel_ReturnsFalse()
        {
            // Arrange
            var context        = this.NewInMemoryDatabase();
            var publisherModel = new PublisherCreateServiceModel
            {
                Description = "TestDescription",
                ImageUrl    = "http://www.test.com",
                Name        = ""
            };

            var publishersService = new PublishersService(context);

            // Act
            var result = await publishersService.CreatePublisherAsync(publisherModel);

            // Assert
            Assert.False(result);
            Assert.False(await context.Publishers.AnyAsync());
        }
示例#4
0
        public async Task CreatePublisherAsync_WithCorrectModel_WorksCorrectly()
        {
            // Arrange
            var context        = this.NewInMemoryDatabase();
            var publisherModel = new PublisherCreateServiceModel
            {
                Description = "TestDescription",
                ImageUrl    = "http://www.test.com",
                Name        = "TestName "
            };

            var publishersService = new PublishersService(context);

            // Act
            var result = await publishersService.CreatePublisherAsync(publisherModel);

            // Assert
            Assert.True(result);

            var publisher = await context.Publishers.SingleOrDefaultAsync();

            Assert.NotNull(publisher);
            Assert.Equal(publisherModel.Name.Trim(), publisher.Name);
        }