Exemplo n.º 1
0
        public async Task ItShouldAddARentWithRentsControllerResultOk()
        {
            var dbContext = CreateDatabase();

            //Arrange
            var sut        = new RentsRepository(dbContext);
            var controller = new RentsController(sut);
            var rent       = new Rents {
                RentId = 1, ClientId = (new Guid()).ToString(), ObjectId = (new Guid()).ToString(), Detailssatus = "RENT", Detailsuntil = "2010/01/05"
            };
            //Act
            //controller.InsertRents(rent);
            var rent1 = new Rents {
                RentId = 2, ClientId = (new Guid()).ToString(), ObjectId = (new Guid()).ToString(), Detailssatus = "RENT", Detailsuntil = "2010/01/05"
            };
            //Act
            //controller.InsertRents(rent1);
            var rent2 = new Rents {
                RentId = 1, ClientId = (new Guid()).ToString(), ObjectId = (new Guid()).ToString(), Detailssatus = "RENT", Detailsuntil = "2010/01/05"
            };
            //Act
            var result = await controller.InsertRents(rent2);

            var          result2 = controller.InsertRents(rent1);
            ObjectResult result1 = result as ObjectResult;
            //Assert
            await Assert.IsAssignableFrom <Task <IActionResult> >(result2);

            Assert.Equal(200, result1.StatusCode);
            //Clean up
            dbContext.Dispose();
        }
Exemplo n.º 2
0
        public async Task ItShouldAddARentWithDataExistRentsControllerResultFails()
        {
            var dbContext = CreateDatabase();

            //Arrange
            var sut        = new RentsRepository(dbContext);
            var controller = new RentsController(sut);
            var rent       = new Rents {
                RentId = 1, ClientId = (new Guid()).ToString(), ObjectId = (new Guid()).ToString(), Detailssatus = "RENT", Detailsuntil = "2010/01/05"
            };
            //Act
            await controller.InsertRents(rent);

            var rent1 = new Rents {
                RentId = 2, ClientId = (new Guid()).ToString(), ObjectId = (new Guid()).ToString(), Detailssatus = "RENT", Detailsuntil = "2010/01/05"
            };
            //Act
            var rent2 = new Rents {
                RentId = 1, ClientId = (new Guid()).ToString(), ObjectId = (new Guid()).ToString(), Detailssatus = "RENT", Detailsuntil = "2010/01/05"
            };
            //Act
            await controller.InsertRents(rent1);

            await Assert.ThrowsAsync <InvalidOperationException>(() => controller.InsertRents(rent2));

            //Clean up
            dbContext.Dispose();
        }
Exemplo n.º 3
0
        public void PutRent()
        {
            var controller = new RentsController(_context);

            controller.PutRent(_rentDTOs[0]);
            controller.PutRent(_rentDTOs[3]);

            var result1 = _context.Rents.FirstOrDefault(r => r.Id == _rentDTOs[0].Id);
            var result2 = _context.Rents.FirstOrDefault(r => r.Id == _rentDTOs[3].Id);

            //Assert
            Assert.Equal(_rentDTOs[0].IsActive, !result1.IsActive);
            Assert.Equal(_rentDTOs[3].IsActive, !result2.IsActive);
            Assert.Equal(_rentDTOs.Count, _context.Rents.Count());
        }
Exemplo n.º 4
0
        public void GetRentsTest()
        {
            var controller = new RentsController(_context);
            var result     = controller.GetRents();

            //Assert
            var objectResult = Assert.IsType <OkObjectResult>(result);
            var model        = Assert.IsAssignableFrom <IEnumerable <RentDTO> >(objectResult.Value);
            var rents        = model.ToList();

            Assert.Equal(3, rents.Count);

            for (int i = 0; i < 3; i++)
            {
                Assert.True(rents[i].IsActive);
            }
        }