示例#1
0
        public async Task MarkDone()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options;

            var fakeUser = new ApplicationUser
            {
                Id       = "fake-000",
                UserName = "******"
            };

            Guid realitem_id;
            Guid fakeitem_id = Guid.NewGuid();

            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                var services = new TodoItemService(inMemoryContext);

                await services.AddItemAsync(new NewTodoItem { Title = "Testing?", DueAt = DateTimeOffset.Now.AddDays(3) }, fakeUser);

                realitem_id = inMemoryContext.Items.FirstAsync().Result.Id;
            }

            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                var services = new TodoItemService(inMemoryContext);

                var fakeresult = services.MarkDoneAsync(fakeitem_id, fakeUser);

                Assert.False(fakeresult.Result);

                var realresult = services.MarkDoneAsync(realitem_id, fakeUser);

                Assert.True(realresult.Result);
            }
        }
示例#2
0
        public async Task MarkDoneTestingWithIncorrectParameter()
        {
            DbContextOptions <ApplicationDbContext> options = new DbContextOptionsBuilder <ApplicationDbContext>()
                                                              .UseInMemoryDatabase(databaseName: "Test_MarkDone").Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(context);

                var fakeUser = new ApplicationUser {
                    Id = "fake-1"
                };

                await service.AddItemAsync(new TodoItem { Title = "DoneTest" }, fakeUser);

                List <TodoItem> tasks = await service.GetIncompleteItemsAsync(fakeUser);

                Assert.Single(tasks);

                Assert.False(await service.MarkDoneAsync(Guid.NewGuid(), fakeUser));
                Assert.False(await service.MarkDoneAsync(tasks[0].Id, new ApplicationUser {
                    Id = "fake-2"
                }));
                Assert.True(await service.MarkDoneAsync(tasks[0].Id, fakeUser));
            }
        }
        public async Task MarksDoneTrue()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "Test_MarksDoneTrue").Options;

            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                var service  = new TodoItemService(inMemoryContext);
                var fakeUser = new ApplicationUser {
                    Id = "fake-000", UserName = "******"
                };
                await service.AddItemAsync(new NewTodoItem()
                {
                    Title = "Testing?"
                }, fakeUser);
            }

            // Use a separate context to read the data back from the DB
            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                Assert.Equal(1, await inMemoryContext.Items.CountAsync());

                var item = await inMemoryContext.Items.FirstAsync();

                var service  = new TodoItemService(inMemoryContext);
                var fakeUser = new ApplicationUser {
                    Id = "fake-000", UserName = "******"
                };

                var resultado = await service.MarkDoneAsync(item.Id, fakeUser);

                Assert.True(resultado);
            }
        }
        public async Task ReturnTrueItemDoesntexist_RTrue()
        {
            //Arrange
            using (var context = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(context);

                var fakeUser = new ApplicationUser
                {
                    Id       = "fake-002",
                    UserName = "******"
                };

                var fakeItem = new TodoItem
                {
                    Title = "Testing?",
                    DueAt = DateTimeOffset.Now.AddDays(0)
                };

                await service.AddItemAsync(fakeItem, fakeUser);

                //Act
                var result = await service.MarkDoneAsync(fakeItem.Id, fakeUser);

                //Assert
                Assert.Equal(true, result);
            }
        }
示例#5
0
        public async Task MarkDoneAsyncReturnsTrueWhenItemIsComplete()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_MarkDoneReturnTrue").Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service  = new TodoItemService(context);
                var fakeUser = new ApplicationUser
                {
                    Id       = "fake-002",
                    UserName = "******"
                };

                var one = await service.AddItemAsync(new TodoItem
                {
                    Title = "Testing?"
                }, fakeUser);

                var itemInDatabase = await context.Items.SingleOrDefaultAsync();

                var result = await service.MarkDoneAsync(itemInDatabase.Id, fakeUser);

                Assert.True(result);
            }
        }
示例#6
0
        public async Task MarkDoneAsyncReturnsTrueForValidId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_MarkDone2")
                          .Options;

            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                var service  = new TodoItemService(inMemoryContext);
                var fakeUser = new ApplicationUser
                {
                    Id       = "fake-000",
                    UserName = "******"
                };

                await service.AddItemAsync(new NewTodoItem { Title = "Testing?" }, fakeUser);

                var item = await inMemoryContext.Items.FirstAsync();

                var success = await service.MarkDoneAsync(item.Id, fakeUser);

                Console.WriteLine(item.Title);
                Assert.True(success);
            }
        }
示例#7
0
        public async Task MarkDoneAsyncMethodWithValidId()
        {
            // Given
            var options        = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options;
            var dateTimeOffset = DateTimeOffset.Now;

            using (var context = new ApplicationDbContext(options))
            {
                var service  = new TodoItemService(context);
                var fakeUser = CreateFakeUser();
                var todoItem = CreateTodoItem(userId: fakeUser.Id, dateTimeOffset);

                await service.AddItemAsync(todoItem, fakeUser);
            }

            using (var context = new ApplicationDbContext(options)) {
                var service         = new TodoItemService(context);
                var fakeUser        = CreateFakeUser();
                var itemsInDatabase = await context.Items.CountAsync();

                var item = await context.Items.FirstAsync();

                bool result = await service.MarkDoneAsync(item.Id, fakeUser);

                Assert.True(result);
            }

            ClearDataBase(options);
        }
        public async Task MarkDoneWrongId()
        {
            var options = new DbContextOptionsBuilder <AspNetCoreTodo.Data.ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service  = new TodoItemService(context);
                var fakeUser = new ApplicationUser
                {
                    Id       = "fake-000",
                    UserName = "******"
                };
                var SecondFakeUser = new ApplicationUser
                {
                    Id       = "fake-001",
                    UserName = "******"
                };

                await service.AddItemAsync(new TodoItem { Title = "Testing?" }, fakeUser);

                var item = await context.Items.FirstAsync();

                Assert.False(await service.MarkDoneAsync(item.Id, SecondFakeUser));
            }
        }
示例#9
0
        public async Task MarkDoneAsync_ReturnsFalse_IfInputIncorrectItemId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_MarkDoneIncorrectId").Options;

            // Set up context (connection to the DB) for writing
            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(inMemoryContext);

                var fakeUser = new ApplicationUser
                {
                    Id       = "fake-001",
                    UserName = "******"
                };

                var incorrectId = Guid.NewGuid();

                await service.AddItemAsync(new NewTodoItem { Title = "MarkDoneIncorrectId" }, fakeUser);

                var result = await service.MarkDoneAsync(incorrectId, fakeUser);

                Assert.False(result);
            }
        }
示例#10
0
        public async Task NoMarkDoneAnItemWithWrongId()
        {
            await SetUp("fake-000", "*****@*****.**", "Testing?", DateTimeOffset.Now.AddDays(3));

            ///Se crea otro contexto, luego se crea otro usuario(con distinto Id), y se verifica:
            ///     1_ Que solo tenga un item.
            ///     2_ Que el item almacenado en la base de datos no este done (false)
            ///     3_ Que falle al marcar como done usando otherFakeUser usando MarkDoneAsync()
            using (var CDB = new ApplicationDbContext(ODB.Options))
            {
                var service       = new TodoItemService(CDB);
                var otherFakeUser = new ApplicationUser {
                    Id = "fake-000-11", UserName = "******"
                };

                var itemInDateBase = await CDB.Items.CountAsync();

                Assert.Equal(1, itemInDateBase);

                var item = await CDB.Items.FirstAsync();

                Assert.False(item.IsDone);

                bool resoult = await service.MarkDoneAsync(item.Id, otherFakeUser);

                Assert.False(resoult);
                Assert.False(item.IsDone);
            }
        }
        public async Task ReturnTrueIfValidItemIsPassedToMarkDoneAsync()
        {
            var options = new DbContextOptionsBuilder <TodoListDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options;

            // Set up a context (connection to the "DB") for writing
            using (var context = new TodoListDbContext(options))
            {
                var service = new TodoItemService(context);

                var fakeUser = new IdentityUser
                {
                    Id       = "fake-000",
                    UserName = "******"
                };

                await service.AddItemAsync(new TodoItem
                {
                    Title = "Testing?"
                }, fakeUser);

                var items = await service.GetIncompleteItemsAsync(fakeUser);

                Assert.True(await service.MarkDoneAsync(items[0].Id, fakeUser));
            }
        }
        public async Task MarkDoneAsyncIncorrectId()
        {
            var options    = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "Test_MarkDone").Options;
            var doneResult = false;
            var fakeUser   = new ApplicationUser
            {
                Id       = "fake-000",
                UserName = "******"
            };
            var fakeItem = NewTodoItem("Testing", fakeUser.Id, DateTimeOffset.Now.AddDays(3));
            var randomId = Guid.NewGuid();

            using (var context = new ApplicationDbContext(options))
            {
                context.Items.Add(fakeItem);
                context.SaveChanges();
                var service = new TodoItemService(context);
                var item    = await context.Items.FirstAsync();

                doneResult = await service.MarkDoneAsync(randomId, fakeUser);
            }

            using (var context = new ApplicationDbContext(options))
            {
                var item = await context.Items.FirstAsync();

                Assert.False(doneResult);
                Assert.False(item.IsDone);
            }

            ClearDataBase(options);
        }
示例#13
0
        public async Task MarkDone()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_MarkDone").Options;

            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(inMemoryContext);

                var fakeUser = new ApplicationUser
                {
                    Id       = "fake - 000",
                    UserName = "******"
                };

                await service.AddItemAsync(new NewTodoItem { Title = "Testing?" }, fakeUser);

                var item = await inMemoryContext.Items.FirstOrDefaultAsync();

                await service.MarkDoneAsync(item.Id);
            }

            // Assertions
            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                Assert.Equal(1, await inMemoryContext.Items.CountAsync());

                var item = await inMemoryContext.Items.FirstAsync();

                Assert.Equal("Testing?", item.Title);
                Assert.True(item.IsDone);
                Assert.True(DateTimeOffset.Now.AddDays(3) - item.DueAt < TimeSpan.FromSeconds(1));
            }
        }
        public async Task MarkItemAsCompleteIfValid()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_MarkItemAsComplete").Options;

            await using var context = new ApplicationDbContext(options);
            var service  = new TodoItemService(context);
            var fakeUser = new ApplicationUser
            {
                Id       = "fake-000",
                UserName = "******"
            };
            await service.AddItemAsync(new TodoItem
            {
                Title = "Testing?"
            }, fakeUser);

            var itemsInDatabase = await context
                                  .Items.CountAsync();

            Assert.Equal(1, itemsInDatabase);
            var item = await context.Items.FirstAsync();

            var result = service.MarkDoneAsync(item.Id, fakeUser);

            Assert.True(result.Result);
        }
示例#15
0
        public async Task MakrDoneAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options;

            // Set up a context (connection to the "DB") for writing
            //using (var context = new ApplicationDbContext(options))
            //{
            //    var service = new TodoItemService(context);
            //}

            using (var context = new ApplicationDbContext(options))
            {
                var service  = new TodoItemService(context);
                var fakeUser = new IdentityUser
                {
                    Id       = "fake-001",
                    UserName = "******"
                };
                context.Users.Add(fakeUser);

                var fakeItem = new TodoItem
                {
                    Id     = Guid.NewGuid(),
                    Title  = "fake item",
                    UserId = fakeUser.Id,
                    IsDone = false
                };
                context.Items.Add(fakeItem);
                await context.SaveChangesAsync();

                var currentItems = await context.Items.Where(i => i.UserId == fakeUser.Id).ToArrayAsync();;
                var expectedItem = await service.GetIncompleteItemsAsync(fakeUser);

                Assert.Equal(currentItems, expectedItem);


                var result = await service.MarkDoneAsync(Guid.NewGuid(), fakeUser);

                var result2 = await service.MarkDoneAsync(fakeItem.Id, fakeUser);

                Assert.Equal(false, result);
                Assert.Equal(true, result2);
            }
        }
        public async Task MarkDoneAsyncReturnsFalseIfIdDoesNotExist()
        {
            using (var context = new ApplicationDbContext(_options))
            {
                var service = new TodoItemService(context);

                var fakeUser = new IdentityUser
                {
                    Id       = "fake-000",
                    UserName = "******"
                };

                await service.AddItemAsync(new TodoItem
                {
                    Title = "Testing2"
                }, fakeUser);
            }

            using (var context = new ApplicationDbContext(_options))
            {
                var service  = new TodoItemService(context);
                var fakeUser = new IdentityUser
                {
                    Id       = "fake-000",
                    UserName = "******"
                };
                var fakeUser2 = new IdentityUser
                {
                    Id       = "fake-001",
                    UserName = "******"
                };

                var item = await context.Items.FirstAsync(a => a.Title == "Testing2");

                var count = await context.Items.CountAsync();

                Console.WriteLine("count" + count.ToString());
                Assert.False(await service.MarkDoneAsync(Guid.NewGuid(), fakeUser));
                Assert.False(await service.MarkDoneAsync(item.Id, fakeUser2));
                Assert.True(await service.MarkDoneAsync(item.Id, fakeUser));
            }
        }
示例#17
0
        public async Task MarkDoneItem()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_MarkDoneItem").Options;

            var fakeUser = new IdentityUser
            {
                Id       = "fake-000",
                UserName = "******"
            };

            using (var context = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(context);

                await context.Items.AddAsync(new TodoItem
                {
                    Title  = "Testing?",
                    UserId = fakeUser.Id
                });

                await context.SaveChangesAsync();
            }

            using (var context = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(context);

                var existUser = await service.MarkDoneAsync(Guid.NewGuid(), new IdentityUser("notExistedUser"));

                Assert.False(existUser);

                var item = await context.Items.FirstAsync();

                var isDoneItem = await service.MarkDoneAsync(item.Id, fakeUser);

                Assert.True(isDoneItem);
            }
        }
示例#18
0
        public async Task MarkAsCompleteWithWrongID()
        {
            //To Configure in memory DB
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(context);

                var result = await service.MarkDoneAsync(Guid.NewGuid(), CreateFakeUser());

                Assert.False(result);
            }
        }
        public async Task MarksDoneFalse()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "Test_MarksDoneFalse").Options;

            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                var service  = new TodoItemService(inMemoryContext);
                var fakeUser = new ApplicationUser {
                    Id = "fake-000", UserName = "******"
                };
                var retorno = await service.MarkDoneAsync(Guid.NewGuid(), fakeUser);

                Assert.False(retorno);
            }
        }
        public async Task NotMarkItemAsCompleteIfIdIsMissing()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_MissingId").Options;

            await using var context = new ApplicationDbContext(options);
            var service  = new TodoItemService(context);
            var fakeUser = new ApplicationUser
            {
                Id       = "fake-000",
                UserName = "******"
            };
            var result = service.MarkDoneAsync(default(Guid), fakeUser);

            Assert.False(result.Result);
        }
示例#21
0
        public void ReturnsFalseIfPassedIdDosentExist()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service  = new TodoItemService(context);
                var fakeUser = new IdentityUser {
                    Id = "fake-000", UserName = "******"
                };
                var faceGuid = new Guid();

                var result = service.MarkDoneAsync(faceGuid, fakeUser).Result;

                Assert.False(result);
            }
        }
示例#22
0
        public async Task MarkDoneAsync_ReturnsTrue_MarksItemAsCompleted_IfInputValidItemIdAndUser_()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_MarkDoneValidItemCompleted").Options;

            var fakeUser = new ApplicationUser
            {
                Id       = "fake-002",
                UserName = "******"
            };

            // Set up context (connection to the DB) for writing
            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(inMemoryContext);

                await service.AddItemAsync(new NewTodoItem { Title = "MarkDoneValidItemCompleted" }, fakeUser);
            }

            // Use a separate context to read the data back from the DB
            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                Assert.Equal(1, await inMemoryContext.Items.CountAsync());

                var item = await inMemoryContext.Items.SingleAsync(i => i.OwnerId == fakeUser.Id);

                var service = new TodoItemService(inMemoryContext);

                var result = await service.MarkDoneAsync(item.Id, fakeUser);

                Assert.True(result);
            }

            // Use a separate context to read the data back from the DB
            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                Assert.Equal(1, await inMemoryContext.Items.CountAsync());

                var item = await inMemoryContext.Items.SingleAsync(i => i.OwnerId == fakeUser.Id);

                Assert.True(item.IsDone);
            }
        }
示例#23
0
        public async Task ReturnsTrueIfValidItemIsMarkedAsComplete()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service  = new TodoItemService(context);
                var fakeUser = new IdentityUser {
                    Id = "fake-000", UserName = "******"
                };
                await service.AddItemAsync(new TodoItem { Title = "Testing?" }, fakeUser);

                var item = await context.Item.FirstOrDefaultAsync();

                var result = service.MarkDoneAsync(item.Id, fakeUser).Result;

                Assert.True(result);
            }
        }
示例#24
0
        public async Task MarkDoneAsyncMethodWithInexistantId()
        {
            // Given
            var options        = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options;
            var dateTimeOffset = DateTimeOffset.Now;

            using (var context = new ApplicationDbContext(options)) {
                var service  = new TodoItemService(context);
                var fakeUser = CreateFakeUser();

                // When
                bool result = await service.MarkDoneAsync(Guid.NewGuid(), fakeUser);

                // Then
                Assert.False(result);
            }

            ClearDataBase(options);
        }
        public async Task MarkDoneCorrectItem()
        {
            var options = new DbContextOptionsBuilder <AspNetCoreTodo.Data.ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options;
            var fakeUser = CreateFakeUsers(0);

            using (var context = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(context);
                await service.AddItemAsync(CreateFakeItem("fake", "sarandi 2020"), fakeUser);
            }
            using (var context = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(context);
                var item    = await context.Items.FirstAsync();

                Assert.True(await service.MarkDoneAsync(item.Id, fakeUser));
            }
        }
示例#26
0
        public async Task MarkAsCompleteWithDueDate()
        {
            //To Configure in memory DB
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service = new TodoItemService(context);
                var item    = await context.Items.FirstAsync();

                await service.MarkDoneAsync(item.Id, CreateFakeUser());


                Assert.True(item.IsDone);
                // Item should be due 3 days from now (give or take a second)
                var difference = DateTimeOffset.Now.AddDays(3) - item.DueAt;
                Assert.True(difference < TimeSpan.FromSeconds(1));
            }
        }
示例#27
0
        public async Task MarkDoneAsyncReturnsFalseIfIdDoesntExist()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_MarkDoneReturnFalse").Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service  = new TodoItemService(context);
                var fakeUser = new ApplicationUser
                {
                    Id       = "fake-001",
                    UserName = "******"
                };


                var result = await service.MarkDoneAsync(new Guid(), fakeUser);

                Assert.False(result);
            }
        }
        public async Task MarkDone_TodoItemIsMarkedDone()
        {
            using (var context = new ApplicationDbContext(Utilities.TestDbContextOptions()))
            {
                // Arrange
                var expectedTodoItem = Items[1];
                await context.AddAsync(expectedTodoItem);

                await context.SaveChangesAsync();

                var service        = new TodoItemService(context);
                var expectedIsDone = expectedTodoItem.IsDone;

                // Act
                await service.MarkDoneAsync(expectedTodoItem.Id, FakeUser);

                // Assert
                var actualTodoItem = await context.Items.FirstOrDefaultAsync(x => x.Title == "Curso React");

                Assert.NotEqual(expectedIsDone, actualTodoItem.IsDone);
            }
        }
示例#29
0
        public async Task MarkDoneAsyncReturnsFalseIfIdDoesNotExistAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_MarkDone")
                          .Options;

            using (var inMemoryContext = new ApplicationDbContext(options))
            {
                var service  = new TodoItemService(inMemoryContext);
                var fakeUser = new ApplicationUser
                {
                    Id       = "fake-000",
                    UserName = "******"
                };

                await service.AddItemAsync(new NewTodoItem { Title = "Testing?" }, fakeUser);

                var success = await service.MarkDoneAsync(Guid.NewGuid(), fakeUser);

                Assert.False(success);
            }
        }