public async Task SavePublisherInsertSuccess_Test()
        {
            PublisherViewModel model = new PublisherViewModel()
            {
                Id      = 0,
                Name    = "abc",
                Address = "123",
                Phone   = "123456789",
                Email   = "*****@*****.**",
                Enabled = true
            };

            var efRepository         = new EfRepository <Publishers>(_dbContext);
            var savePublisherCommand = new SavePublisherCommand(efRepository);
            var result = await savePublisherCommand.ExecuteAsync(model);

            var getListPublisher = new GetListPublisherQuery(efRepository);
            var publisher        = (await getListPublisher.ExecuteAsync()).FirstOrDefault();

            Assert.Equal(result.Data, model.Id);
            Assert.Equal(model.Name, publisher.Name);
            Assert.Equal(model.Address, publisher.Address);
            Assert.Equal(model.Phone, publisher.Phone);
            Assert.Equal(model.Email, publisher.Email);
            Assert.Equal(model.Enabled, publisher.Enabled);
        }
        public async Task SavePublisherUpdateSuccess_Test()
        {
            Publishers publisher1 = new Publishers()
            {
                Id      = 1,
                Name    = "abc",
                Address = "123",
                Phone   = "123456789",
                Email   = "*****@*****.**"
            };

            _dbContext.Set <Publishers>().Add(publisher1);

            PublisherViewModel model = new PublisherViewModel()
            {
                Id      = 1,
                Name    = "abc123",
                Address = "123",
                Phone   = "123456789",
                Email   = "*****@*****.**"
            };

            await _dbContext.SaveChangesAsync();

            var efRepository         = new EfRepository <Publishers>(_dbContext);
            var savePublisherCommand = new SavePublisherCommand(efRepository);
            var result = await savePublisherCommand.ExecuteAsync(model);

            var getListPublisher = new GetListPublisherQuery(efRepository);
            var Publisher        = (await getListPublisher.ExecuteAsync()).FirstOrDefault();

            Assert.Equal(result.Data, model.Id);
            Assert.Equal(model.Name, Publisher.Name);
        }
Beispiel #3
0
        public async Task GetListPublisher_Test()
        {
            var publisher1 = new Publishers
            {
                Id      = 1,
                Name    = "publishers1",
                Enabled = true
            };

            _dbContext.Set <Publishers>().Add(publisher1);

            var publisher2 = new Publishers
            {
                Id      = 2,
                Name    = "publisher2",
                Enabled = false
            };

            _dbContext.Set <Publishers>().Add(publisher2);

            await _dbContext.SaveChangesAsync();

            var efRepository          = new EfRepository <Publishers>(_dbContext);
            var getListPublisherQuery = new GetListPublisherQuery(efRepository);
            var publishers            = await getListPublisherQuery.ExecuteAsync();

            Assert.NotNull(publishers);
            Assert.Equal(2, publishers.Count);
        }