コード例 #1
0
        public async Task GetAllAsync_WithValidData_WorksCorrectly()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var expectedResults = new[] { "Subject1", "Subject2", "Subject3" }
            .OrderBy(s => s)
            .ToArray();

            foreach (var model in expectedResults)
            {
                context.ContactMessages.Add(new ContactMessage()
                {
                    FullName = "TestFullName",
                    Email    = "*****@*****.**",
                    Subject  = model,
                    Message  = "MessageTest"
                });
            }

            await context.SaveChangesAsync();

            var contactMessagesService = new ContactMessagesService(new EfRepository <ContactMessage>(context),
                                                                    new EfRepository <User>(context));

            var actualResults = (await contactMessagesService.GetAllAsync())
                                .Select(s => s.Subject)
                                .OrderBy(s => s)
                                .ToArray();

            Assert.Equal(expectedResults, actualResults);
        }
コード例 #2
0
        public async Task GetAllAsync_WithNoData_ReturnsNull()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var contactMessagesService = new ContactMessagesService(new EfRepository <ContactMessage>(context),
                                                                    new EfRepository <User>(context));

            var actualResults = (await contactMessagesService.GetAllAsync());

            Assert.Empty(actualResults);
        }
コード例 #3
0
        public async Task GetAllAsync_WithNoMessages_ReturnsEmptyEnumerable()
        {
            // Arrange
            const int expectedCount = 0;

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var contactMessagesService = new ContactMessagesService(new EfRepository <ContactMessage>(context), new EfRepository <PoolItUser>(context));

            // Act
            var actualCount = (await contactMessagesService.GetAllAsync()).Count();

            // Assert
            Assert.Equal(expectedCount, actualCount);
        }
コード例 #4
0
        public async Task GetAllAsync_WithMessages_WorksCorrectly()
        {
            // Arrange
            const int expectedCount = 2;

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            await context.ContactMessages.AddRangeAsync(
                new ContactMessage
            {
                Email    = "*****@*****.**",
                FullName = "Test Name",
                Subject  = "Test Subject",
                Message  = "Test Message"
            },
                new ContactMessage
            {
                Email    = null,
                FullName = null,
                Subject  = "Test Subject",
                Message  = "Test Message",
                User     = new PoolItUser
                {
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    FirstName = "Test",
                    LastName  = "User"
                }
            }
                );

            await context.SaveChangesAsync();

            var contactMessagesService = new ContactMessagesService(new EfRepository <ContactMessage>(context), new EfRepository <PoolItUser>(context));

            // Act
            var actualCount = (await contactMessagesService.GetAllAsync()).Count();

            // Assert
            Assert.Equal(expectedCount, actualCount);
        }