Exemple #1
0
 public void Setup()
 {
     System.Data.Common.DbConnection connection = DbConnectionFactory.CreatePersistent(Guid.NewGuid().ToString());
     _ctx        = new FakeDbContext(connection);
     _repository = new SpendingRepository(_ctx);
     _spending   = ObjectMother.GetValidSpending();
     //Seed
     _spendingSeed = ObjectMother.GetValidSpending();
     _ctx.Spendings.Add(_spendingSeed);
     _ctx.SaveChanges();
 }
 public UnitOfWork(RentACarContext context)
 {
     this._rentACarContext  = context;
     carRepository          = new CarRepository(_rentACarContext);
     cartrackingRepository  = new CartrackingRepository(_rentACarContext);
     companyRepository      = new CompanyRepository(_rentACarContext);
     customerRepository     = new CustomerRepository(_rentACarContext);
     personRepository       = new PersonRepository(_rentACarContext);
     rentalRepository       = new RentalRepository(_rentACarContext);
     roleRepository         = new RoleRepository(_rentACarContext);
     spendingRepository     = new SpendingRepository(_rentACarContext);
     spendingTypeRepository = new SpendingTypeRepository(_rentACarContext);
     userRepository         = new UserRepository(_rentACarContext);
 }
Exemple #3
0
        public void AddSpendingMissingUser_Fails()
        {
            int missingUserId = 42;

            // Arrange
            using (SpendingContext spendingContext = new SpendingContext())
            {
                SpendingRepository spendingRepository = new SpendingRepository(spendingContext);
                SpendingController sut = new SpendingController(spendingRepository);

                // Act
                BadRequestResult actionResult = sut.AddSpending(missingUserId, DateTime.UtcNow.AddDays(-1), 100, "USD", "Misc", "Armor") as BadRequestResult;

                // Assert
                Assert.Equal(400, actionResult.StatusCode);
            }
        }
Exemple #4
0
        public void ListOrderedByUserId()
        {
            // Arrange
            using (SpendingContext spendingContext = new SpendingContext())
            {
                SpendingRepository spendingRepository = new SpendingRepository(spendingContext);
                SpendingController sut = new SpendingController(spendingRepository);

                // Act
                ObjectResult actionResult = sut.ListByUserId(1, "Date") as ObjectResult;


                // Assert
                IEnumerable <SpendingDto> spendings = (IEnumerable <SpendingDto>)actionResult.Value;
                Assert.Empty(spendings);
            }
        }
Exemple #5
0
        public void ListOrderedWithWrongOrderBy_Fails()
        {
            string wrongOrderBy = "loki";

            // Arrange
            using (SpendingContext spendingContext = new SpendingContext())
            {
                SpendingRepository spendingRepository = new SpendingRepository(spendingContext);
                SpendingController sut = new SpendingController(spendingRepository);

                // Act
                BadRequestResult actionResult = sut.ListByUserId(1, wrongOrderBy) as BadRequestResult;

                // Assert
                Assert.Equal(400, actionResult.StatusCode);
            }
        }
Exemple #6
0
        public void AddSpendingAndListIt()
        {
            // Arrange
            using (SpendingContext spendingContext = new SpendingContext())
            {
                SpendingRepository spendingRepository = new SpendingRepository(spendingContext);
                SpendingController sut = new SpendingController(spendingRepository);

                // Act
                IStatusCodeActionResult actionResult = sut.AddSpending(1, DateTime.UtcNow.AddDays(-1), 100, "USD", "Misc", "Armor") as IStatusCodeActionResult;

                // Assert
                Assert.Equal(200, actionResult.StatusCode);
                ObjectResult listResult             = sut.ListByUserId(1, "Date") as ObjectResult;
                IEnumerable <SpendingDto> spendings = (IEnumerable <SpendingDto>)listResult.Value;
                Assert.Single(spendings);
            }
        }