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();
        }