public async Task Setup() { _categories = CategoryBuilder.WithLibrary(LibraryId).WithBooks(3).Build(4); _selectedCategory = _categories.First(); _response = await Client.GetAsync($"/libraries/{LibraryId}/categories/{_selectedCategory.Id}"); _assert = CategoryAssert.FromResponse(_response).InLibrary(LibraryId); }
public async Task Setup() { _category = new CategoryView { Name = RandomData.Name }; _response = await Client.PostObject($"/libraries/{LibraryId}/categories", _category); _assert = CategoryAssert.FromResponse(_response).InLibrary(LibraryId); }
public async Task Setup() { _expectedCategory = new CategoryView { Id = RandomData.Number, Name = RandomData.Name }; _response = await Client.PutObject($"/libraries/{LibraryId}/categories/{_expectedCategory.Id}", _expectedCategory); _assert = CategoryAssert.FromResponse(_response).InLibrary(LibraryId); }
public void TryGetByLabelTest() { // Getting existing category { string name = "The name"; var target = new CategoricalVariable(name) { { 0.0, "Zero" }, { 1.0, "One" }, { 2.0, "Two" } }; Category expectedCategory; bool actualFlag, expectedFlag; string categoryLabel; categoryLabel = "One"; actualFlag = target.TryGet( categoryLabel, out Category actualCategory); expectedFlag = true; expectedCategory = new Category(1.0, categoryLabel); Assert.AreEqual(expectedFlag, actualFlag); CategoryAssert.AreEqual(expectedCategory, actualCategory); } // Getting not existing category { string name = "The name"; var target = new CategoricalVariable(name) { { 0.0, "Zero" }, { 1.0, "One" }, { 2.0, "Two" } }; Category expectedCategory; bool actualFlag, expectedFlag; string categoryLabel; categoryLabel = "Three"; actualFlag = target.TryGet( categoryLabel, out Category actualCategory); expectedFlag = false; expectedCategory = null; Assert.AreEqual(expectedFlag, actualFlag); CategoryAssert.AreEqual(expectedCategory, actualCategory); } }
public void ConstructorTest() { double expectedCode = 1.2; string expectedLabel = "The label"; var target = new Category(expectedCode, expectedLabel); CategoryAssert.IsStateAsExpected( target, expectedCode, expectedLabel); }
public void TryGetByCodeTest() { // Getting existing category { string name = "The name"; var target = new CategoricalVariable(name) { { 0.0, "Zero" }, { 1.0, "One" }, { 2.0, "Two" } }; bool actualFlag, expectedFlag; double categoryCode; categoryCode = 1.0; actualFlag = target.TryGet( categoryCode, out Category actualCategory); expectedFlag = true; Category expectedCategory = new(categoryCode, "One"); Assert.AreEqual(expectedFlag, actualFlag); CategoryAssert.AreEqual(expectedCategory, actualCategory); } // Getting not existing category { string name = "The name"; var target = new CategoricalVariable(name) { { 0.0, "Zero" }, { 1.0, "One" }, { 2.0, "Two" } }; Category expectedCategory; bool actualFlag, expectedFlag; double categoryCode; categoryCode = 3.0; actualFlag = target.TryGet( categoryCode, out Category actualCategory); expectedFlag = false; expectedCategory = null; Assert.AreEqual(expectedFlag, actualFlag); CategoryAssert.AreEqual(expectedCategory, actualCategory); } }
private static void AssertBudgetEqual(Budget budget, Budget newBudget, int toYear, int toMonth) { Assert.Equal(new DateTime(toYear, toMonth, 1), newBudget.StartDate); Assert.NotEqual(budget.Id, newBudget.Id); Assert.Equal(budget.Categories.Count, newBudget.Categories.Count); foreach (var category in budget.Categories) { var actualCategory = newBudget.Categories.Single(c => c.Name == category.Name); CategoryAssert.EqualWithoutActuals(category, actualCategory); } }
public async Task Setup() { _categories = CategoryBuilder.WithLibrary(LibraryId).WithBooks(3).Build(4); _selectedCategory = _categories.PickRandom(); _expectedCategory = new CategoryView { Id = _selectedCategory.Id, Name = RandomData.Name }; _response = await Client.PutObject($"/libraries/{LibraryId}/categories/{_selectedCategory.Id}", _expectedCategory); _assert = CategoryAssert.FromResponse(_response).InLibrary(LibraryId); }
public async Task Execute_ShouldGetCategoryValues() { _budget.Categories = new List <Category> { new Category { Name = "Bill", BudgetLineItems = new List <BudgetLineItem> { new BudgetLineItem { Name = "Jack" } } } }; var viewModel = await Execute(); CategoryAssert.Equal(_budget.Categories[0], viewModel.Categories[0]); }
public void ShouldHaveDeletedCategory() { CategoryAssert.ShouldHaveDeletedCategory(LibraryId, _selectedCategory.Id, DatabaseConnection); }
public void ShouldNotHaveDeletedTheCategory() { var cats = DatabaseConnection.GetCategoriesByBook(_expected.Id); cats.ForEach(cat => CategoryAssert.ShouldNotHaveDeletedCategory(LibraryId, cat.Id, DatabaseConnection)); }
public void GetEnumeratorTest() { // IEnumerable.GetEnumerator { var target = new CategoricalVariable("V") { 0, 1, 2 }; IEnumerable enumerable = (IEnumerable)target; IEnumerator enumerator = enumerable.GetEnumerator(); object current; int index = 0; while (enumerator.MoveNext()) { current = enumerator.Current; Assert.AreEqual(target.Categories[index], (Category)current); index++; } // reset enumerator.Reset(); // dispose enumerator = null; GC.Collect(10, GCCollectionMode.Forced); } // IEnumerable<Category>.GetEnumerator { var target = new CategoricalVariable("V") { 0, 1, 2 }; IEnumerable <Category> enumerable = (IEnumerable <Category>)target; IEnumerator <Category> enumerator = enumerable.GetEnumerator(); int index = 0; Category current; while (enumerator.MoveNext()) { current = enumerator.Current; Assert.AreEqual(target.Categories[index], current); index++; } // reset enumerator.Reset(); // dispose enumerator.Dispose(); } // IEnumerable<Category>.Current returns null { var target = new CategoricalVariable("V") { 0, 1, 2 }; var enumerable = (IEnumerable <Category>)target; var enumerator = enumerable.GetEnumerator(); Assert.IsNull(enumerator.Current); } // IEnumerable.Current fails { string STR_EXCEPT_ENU_OUT_OF_BOUNDS = "Enumeration has either not started or has already finished."; var target = new CategoricalVariable("V") { 0, 1, 2 }; var enumerable = (IEnumerable)target; var enumerator = enumerable.GetEnumerator(); ExceptionAssert.Throw( () => { object current = enumerator.Current; }, expectedType: typeof(InvalidOperationException), expectedMessage: STR_EXCEPT_ENU_OUT_OF_BOUNDS); } // valid input { var target = new CategoricalVariable("V") { { 0, "A" }, { 1, "B" }, { 2, "C" } }; Category[] expected = new Category[3] { new Category(0, "A"), new Category(1, "B"), new Category(2, "C") }; int index = 0; foreach (var category in target) { CategoryAssert.AreEqual( expected: expected[index], actual: category); index++; } } }