示例#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 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());
        }
示例#3
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);
        }