public async Task DeleteReturnsTrue()
        {
            Mock <DeleteResult> mockResult = new Mock <DeleteResult>();

            mockResult.SetupGet(x => x.IsAcknowledged).Returns(true);
            _mockCollection.Setup(x => x.DeleteOneAsync(
                                      It.IsAny <FilterDefinition <Room> >(),
                                      It.IsAny <CancellationToken>()
                                      )).ReturnsAsync(mockResult.Object);
            _mockContext.Setup(x => x.MongoCollection).Returns(_mockCollection.Object);
            var repo   = new RoomRepository(_mockContext.Object);
            var result = await repo.DeleteAsync(_roomEntity.Id.ToString()).ConfigureAwait(true);

            Assert.True(result);
        }
Ejemplo n.º 2
0
        public override async Task DeleteWorksAsync()
        {
            Room roomSaved = null;
            int  id        = 0;

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project15Context>()
                          .UseInMemoryDatabase("db_room_test_delete").Options;

            using (var db = new Project15Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project15Context(options))
            {
                var repo = new RoomRepository(db);

                //Create customer
                Room room = new Room {
                    Beds = 1, Cost = 50, RoomType = "Standard"
                };
                roomSaved = await repo.CreateAsync(room);

                await repo.SaveChangesAsync();

                id = roomSaved.Id;
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project15Context(options))
            {
                var  repo = new RoomRepository(db);
                Room room = await repo.GetByIdAsync(id);

                Assert.NotEqual(0, room.Id); // should get some generated ID
                Assert.Equal(roomSaved.Id, room.Id);
                Assert.Equal(1, room.Beds);
                Assert.Equal(50, room.Cost);
                Assert.Equal("Standard", room.RoomType);

                await repo.DeleteAsync(id);

                await repo.SaveChangesAsync();

                room = await repo.GetByIdAsync(id);

                Assert.Null(room);
            }
        }
Ejemplo n.º 3
0
        public override async Task DeleteWithIdThatDoesntExistThrowsExceptionAsync()
        {
            int id = 1000;

            var options = new DbContextOptionsBuilder <Project15Context>()
                          .UseInMemoryDatabase("dp_room_test-delete").Options;

            // arrange (use the context directl - we assume that it works)
            using (var db = new Project15Context(options));


            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project15Context(options))
            {
                var repo = new RoomRepository(db);

                Room room = await repo.GetByIdAsync(id);

                Assert.Null(room);

                await Assert.ThrowsAsync <ArgumentException>(() => repo.DeleteAsync(id));
            }
        }