예제 #1
0
        public async Task Test_List()
        {
            var console = new Mock <IMyConsole>(MockBehavior.Loose);
            var ctx     = new MyDbContext(InMemoryDbCreator.CreateInMemoryOptions <MyDbContext>("Test_List"));
            await ctx.ToDos.AddRangeAsync(new ToDo()
            {
                Id      = Guid.NewGuid(),
                Text    = "Existing1",
                Written = DateTime.UtcNow
            }, new ToDo()
            {
                Id      = Guid.NewGuid(),
                Text    = "Existing2",
                Written = DateTime.UtcNow
            });

            await ctx.SaveChangesAsync();

            var list = new ListTodos(NullLoggerFactory.Instance, ctx, console.Object);

            console.Setup(p => p.WriteLine(It.IsAny <string>()));
            await list.ListAsync();

            console.Verify(p => p.WriteLine("Existing1"), Times.Once);
            console.Verify(p => p.WriteLine("Existing2"), Times.Once);
        }
예제 #2
0
        public async Task Test_EmptyList()
        {
            var console = new Mock <IMyConsole>(MockBehavior.Loose);
            var ctx     = new MyDbContext(InMemoryDbCreator.CreateInMemoryOptions <MyDbContext>("Test_EmptyList"));
            var list    = new ListTodos(NullLoggerFactory.Instance, ctx, console.Object);

            console.Setup(p => p.WriteLine(It.IsAny <string>()));
            await list.ListAsync();

            console.Verify(p => p.WriteLine("No TODOs in database.  Add one and try again."), Times.Once);
        }
예제 #3
0
        public async Task Test_Add()
        {
            var console = new Mock <IMyConsole>(MockBehavior.Loose);
            var ctx     = new MyDbContext(InMemoryDbCreator.CreateInMemoryOptions <MyDbContext>("Test_Add"));
            var add     = new AddTodos(NullLoggerFactory.Instance, ctx, console.Object);

            console.Setup(p => p.WriteLine(It.IsAny <string>()));
            console.Setup(p => p.ReadLine()).Returns("New TODO");
            await add.AwaitAddAsync();

            console.Verify(p => p.WriteLine("Enter a todo item, then press enter:"), Times.Once);
            console.Verify(p => p.ReadLine(), Times.Once);
            Assert.AreEqual(1, await ctx.ToDos.CountAsync());
            Assert.AreEqual("New TODO", await ctx.ToDos.Select(p => p.Text).FirstAsync());
        }