Exemplo n.º 1
0
 private void InitializeDatabase()
 {
     using (SpendingContext spendingContext = new SpendingContext())
     {
         spendingContext.Database.EnsureDeleted();
         spendingContext.Database.EnsureCreated();
         spendingContext.SaveChanges();
     }
 }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        // For dev purpose only
        private void DatabaseSetup()
        {
            IConfigurationSection databaseSetupSection = this.Configuration.GetSection("DatabaseSetup");

            using (SpendingContext db = new SpendingContext())
            {
                if (databaseSetupSection["EnsureDeleted"].ToUpperInvariant() == "TRUE")
                {
                    db.Database.EnsureDeleted();
                }
                if (databaseSetupSection["EnsureCreated"].ToUpperInvariant() == "TRUE")
                {
                    db.Database.EnsureCreated();
                }

                db.SaveChanges();
            }
        }