public void GetByKey_ReturnsIncomeAndExpense() { string expectedTransactionTypesJson = File.ReadAllText(TestConfiguration.MockDataFolderPath + @"TransactionTypes.json"); var expectedTransactionTypes = JsonConvert.DeserializeObject <List <TransactionType> >(expectedTransactionTypesJson); var expectedIncome = expectedTransactionTypes .First(t => t.Name == TransactionType.Options.Income.ToString()); var expectedExpense = expectedTransactionTypes .First(t => t.Name == TransactionType.Options.Expense.ToString()); TransactionTypeRepository .Setup(r => r.GetByKey(TransactionType.Options.Income.ToString())).Returns(expectedIncome); TransactionTypeRepository .Setup(r => r.GetByKey(TransactionType.Options.Expense.ToString())).Returns(expectedExpense); var actualIncome = TransactionTypeService.GetByKey(TransactionType.Options.Income.ToString()); var actualExpense = TransactionTypeService.GetByKey(TransactionType.Options.Expense.ToString()); Assert.NotNull(actualIncome); Assert.NotNull(actualExpense); Assert.Equal(actualIncome.Name, expectedIncome.Name); Assert.Equal(actualIncome.IconUrl, expectedIncome.IconUrl); Assert.Equal(actualExpense.Name, expectedExpense.Name); Assert.Equal(actualExpense.IconUrl, expectedExpense.IconUrl); }
public void GetAll_ReturnsAll() { string expectedTransactionTypesJson = File.ReadAllText(TestConfiguration.MockDataFolderPath + @"TransactionTypes.json"); var expectedTransactionTypes = JsonConvert.DeserializeObject <List <TransactionType> >(expectedTransactionTypesJson); TransactionTypeRepository.Setup(r => r.GetAll()).Returns(expectedTransactionTypes); var actualTransactionTypes = TransactionTypeService.GetAll(); Assert.NotNull(actualTransactionTypes); Assert.Equal(expectedTransactionTypes.Count, actualTransactionTypes.Count()); }
public async Task Create_ReturnsNewCategory() { const int testingUserId = 1; string transactionTypesJson = File.ReadAllText(TestConfiguration.MockDataFolderPath + @"TransactionTypes.json"); var transactionTypes = JsonConvert.DeserializeObject <List <TransactionType> >(transactionTypesJson); string usersJson = File.ReadAllText(TestConfiguration.MockDataFolderPath + @"Users.json"); var user = JsonConvert.DeserializeObject <List <User> >(usersJson).First(u => u.Id == testingUserId); var category = new Category { Name = "Test category", TypeName = TransactionType.Options.Income.ToString(), IsCustom = true }; UserContext.Setup(c => c.GetUserId()).Returns(testingUserId); UserRepository.Setup(u => u.GetByKey(testingUserId)).Returns(user); TransactionTypeRepository .Setup(t => t.GetByKey(TransactionType.Options.Income.ToString())) .Returns(transactionTypes.First(t => t.Name == TransactionType.Options.Income.ToString())); TransactionTypeRepository .Setup(t => t.GetByKey(TransactionType.Options.Expense.ToString())) .Returns(transactionTypes.First(t => t.Name == TransactionType.Options.Expense.ToString())); CategoryRepository .Setup(c => c.Create(category)) .ReturnsAsync(category); var categoryService = new CategoryService(ContextProvider.Object, UserContext.Object, EventManager.Object); var resultCategory = await categoryService.Create(category); Assert.NotNull(resultCategory); Assert.NotNull(resultCategory.Type); Assert.NotNull(resultCategory.User); Assert.Equal(category.Name, resultCategory.Name); Assert.Equal(category.IsCustom, resultCategory.IsCustom); Assert.Equal(category.Type.Name, resultCategory.Type.Name); Assert.Equal(category.User.Id, resultCategory.User.Id); Assert.Equal("/static/icons/categories/unknown.png", resultCategory.IconUrl); }