/// <summary> /// Invokes the window with statistical data for the users. /// </summary> internal void ShowStats() { try { StatsView statsView = new StatsView(); StatsViewModel statsViewModel = new StatsViewModel(this.customers); statsView.DataContext = statsViewModel; statsView.ShowDialog(); } catch (Exception ex) { InfoDialogViewModel.ShowDialog(ex.Message, "Unhandled Exception"); Log.LogException(ex, "MainViewModel.cs"); } }
/// <summary> /// Invokes the window with statistical data for the users. /// </summary> internal void ShowStats() { try { StatsView statsView = new StatsView(); StatsViewModel statsViewModel = new StatsViewModel(this.customers); statsView.DataContext = statsViewModel; statsView.ShowDialog(); } catch (Exception ex) { InfoDialogViewModel.ShowDialog(ex.Message, "Unhandled Exception"); Log.LogException(ex, "MainViewModel.cs"); } }
public void StatsByLocationReturnComaAndSpaceSeparateCountryAndStateDescription() { Customer customer = TestHelpers.GetSampleCustomer(); List<Customer> customers = new List<Customer>() { customer }; StatsViewModel viewModel = new StatsViewModel(customers); viewModel.SelectedStatsType = StatsType.Location; string expectedDescription = customer.Country + ", " + customer.State; decimal expectedValue = 1m; List<KeyValuePair<string, decimal>> expectedResult = new List<KeyValuePair<string, decimal>>() { new KeyValuePair<string,decimal>(expectedDescription, expectedValue) }; CollectionAssert.AreEquivalent(expectedResult, viewModel.StatsData); List<KeyValuePair<string, decimal>> incorrectList = new List<KeyValuePair<string, decimal>>() { new KeyValuePair<string,decimal>("United States, Alaska ", 1) }; CollectionAssert.AreNotEquivalent(incorrectList, viewModel.StatsData); List<KeyValuePair<string, decimal>> incorrectList2 = new List<KeyValuePair<string, decimal>>() { new KeyValuePair<string,decimal>("United States,Alaska",1) }; CollectionAssert.AreNotEquivalent(incorrectList2, viewModel.StatsData); List<KeyValuePair<string, decimal>> incorrectList3 = new List<KeyValuePair<string, decimal>>() { new KeyValuePair<string,decimal>("Alaska, United States",1) }; CollectionAssert.AreNotEquivalent(incorrectList3, viewModel.StatsData); }
public void StatsByLocationReturnCorrectNumberOfUsersPerLocation() { List<Customer> customers = TestHelpers.GetSampleCustomersList(); StatsViewModel viewModel = new StatsViewModel(customers); viewModel.SelectedStatsType = StatsType.Location; List<KeyValuePair<string, decimal>> expectedList = new List<KeyValuePair<string, decimal>>() { new KeyValuePair<string,decimal>("United States, Alaska", 2), new KeyValuePair<string,decimal>("United States, Florida", 1), new KeyValuePair<string,decimal>("United States, Washington", 1), }; CollectionAssert.AreEquivalent(expectedList, viewModel.StatsData); List<KeyValuePair<string, decimal>> incorrectList = new List<KeyValuePair<string, decimal>>() { new KeyValuePair<string,decimal>("UK, Surrey", 1), new KeyValuePair<string,decimal>("United States, Florida", 1), new KeyValuePair<string,decimal>("United States, Washington", 1), }; CollectionAssert.AreNotEquivalent(incorrectList, viewModel.StatsData); }
public void StatsByLocationPercentShouldToupleWithDescriptionValuePercentage() { List<Customer> customers = TestHelpers.GetSampleCustomersList(); StatsViewModel viewModel = new StatsViewModel(customers); viewModel.SelectedStatsType = StatsType.Location; List<Tuple<string, decimal, decimal>> expectedList = new List<Tuple<string, decimal, decimal>>() { new Tuple<string,decimal,decimal>("United States, Alaska", 2, 50), new Tuple<string,decimal,decimal>("United States, Florida", 1, 25), new Tuple<string,decimal,decimal>("United States, Washington", 1, 25) }; CollectionAssert.AreEquivalent(expectedList, viewModel.StatsDataPercent); List<Tuple<string, decimal, decimal>> incorrectList = new List<Tuple<string, decimal, decimal>>() { new Tuple<string,decimal,decimal>("United States, Alaska", 2, 0), new Tuple<string,decimal,decimal>("United States, Florida", 1, 0), new Tuple<string,decimal,decimal>("United States, Washington", 1, 0) }; CollectionAssert.AreNotEquivalent(incorrectList, viewModel.StatsData); }
public void StatsByLocationPercentRoundValueToTwoDecimalPlaces2() { List<Customer> customers = new List<Customer>() { TestHelpers.GetSampleCustomer(), TestHelpers.GetSampleCustomer(), TestHelpers.GetSampleCustomer(), }; customers[0].Country = "United States"; customers[1].Country = "United States"; customers[2].Country = "United States"; customers[0].State = "Washington"; customers[1].State = "Alaska"; customers[2].State = "Alaska"; StatsViewModel viewModel = new StatsViewModel(customers); viewModel.SelectedStatsType = StatsType.Location; List<Tuple<string, decimal, decimal>> expectedList = new List<Tuple<string, decimal, decimal>>() { new Tuple<string,decimal,decimal>("United States, Alaska", 2, 66.67m), new Tuple<string,decimal,decimal>("United States, Washington", 1, 33.33m), }; CollectionAssert.AreEquivalent(expectedList, viewModel.StatsDataPercent); }
public void StatsByCategoryReturnCorrectNumberOfUsersPerCategory() { List<Customer> customers = TestHelpers.GetSampleCustomersList(); StatsViewModel viewModel = new StatsViewModel(customers); viewModel.SelectedStatsType = StatsType.Category; List<KeyValuePair<string, decimal>> expectedList = new List<KeyValuePair<string, decimal>>() { new KeyValuePair<string,decimal>("A", 2), new KeyValuePair<string,decimal>("B", 2), }; CollectionAssert.AreEquivalent(expectedList, viewModel.StatsData); List<KeyValuePair<string, decimal>> incorrectList = new List<KeyValuePair<string, decimal>>() { new KeyValuePair<string,decimal>("A", 1), new KeyValuePair<string,decimal>("B", 1), new KeyValuePair<string,decimal>("C", 1), }; CollectionAssert.AreNotEquivalent(incorrectList, viewModel.StatsData); }
public void StatsByCategoryPercentShouldToupleWithDescriptionValuePercentage() { List<Customer> customers = TestHelpers.GetSampleCustomersList(); StatsViewModel viewModel = new StatsViewModel(customers); viewModel.SelectedStatsType = StatsType.Category; List<Tuple<string, decimal, decimal>> expectedList = new List<Tuple<string, decimal, decimal>>() { new Tuple<string,decimal,decimal>("A", 2, 50), new Tuple<string,decimal,decimal>("B", 2, 50), }; CollectionAssert.AreEquivalent(expectedList, viewModel.StatsDataPercent); List<Tuple<string, decimal, decimal>> incorrectList = new List<Tuple<string, decimal, decimal>>() { new Tuple<string,decimal,decimal>("A", 2, 75), new Tuple<string,decimal,decimal>("B", 2, 25), }; CollectionAssert.AreNotEquivalent(incorrectList, viewModel.StatsData); }
public void StatsByCategoryPercentRoundValueToTwoDecimalPlaces2() { List<Customer> customers = new List<Customer>() { TestHelpers.GetSampleCustomer(), TestHelpers.GetSampleCustomer(), TestHelpers.GetSampleCustomer(), }; customers[0].Category = Category.A; customers[1].Category = Category.B; customers[2].Category = Category.B; StatsViewModel viewModel = new StatsViewModel(customers); viewModel.SelectedStatsType = StatsType.Category; List<Tuple<string, decimal, decimal>> expectedList = new List<Tuple<string, decimal, decimal>>() { new Tuple<string,decimal,decimal>("A", 1, 33.33m), new Tuple<string,decimal,decimal>("B", 2, 66.67m), }; CollectionAssert.AreEquivalent(expectedList, viewModel.StatsDataPercent); }