Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }