示例#1
0
        public async Task AllWithNullId()
        {
            ApplicationDbContext dbContextMessage = new ApplicationDbContext(new DbContextOptionsBuilder <ApplicationDbContext>()
                                                                             .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
            var service = new MessageService(new EfDeletableEntityRepository <Message>(dbContextMessage));

            for (int i = 1; i <= 5; i++)
            {
                await service.AddAsync(
                    "Ivan Ivanov",
                    "content",
                    "1");
            }

            var results = service.All <IndexMessageViewModel>(null);

            int count = 0;

            foreach (var result in results)
            {
                count++;
            }

            Assert.Equal(0, count);
            dbContextMessage.Database.EnsureDeleted();
            dbContextMessage.Dispose();
        }
示例#2
0
        public async void All_ShouldReturnRecords()
        {
            var mock    = new ServiceMockFacade <IMessageService, IMessageRepository>();
            var records = new List <Message>();

            records.Add(new Message());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            var service = new MessageService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.MessageModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALMessageMapperMock,
                                             mock.DALMapperMockFactory.DALMessengerMapperMock);

            List <ApiMessageServerResponseModel> response = await service.All();

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }