public void TestChartAsync_NormallyExcuted_ShouldReturnTrue() { var stub = new StubIChartUtil(MockBehavior.Strict); viewModel.ChartDao = stub; int except1 = 0, except2 = 0; stub.ChartLengendAsync(async(sites) => { ObservableCollection <ChartLengend> s = new ObservableCollection <ChartLengend>(); await Task.CompletedTask; except1 = sites.Count; return(s); }, Times.Once); stub.CacuChartAsync(async(sites, logs) => { ObservableCollection <ObservableCollection <Chart1> > data1 = new ObservableCollection <ObservableCollection <Chart1> >(); ObservableCollection <BarChartData> data2 = new ObservableCollection <BarChartData>(); except2 = sites.Count + logs.Count; await Task.CompletedTask; return(new Tuple <ObservableCollection <ObservableCollection <Chart1> >, ObservableCollection <BarChartData> >(data1, data2)); }, Times.Once); Assert.IsTrue(viewModel.ChartAsync(Sites, Logs).Result); Assert.AreEqual(5, except1); Assert.AreEqual(10, except2); }
public void TestAcceptClickAsync_NumberOfSiteLE5_ShouldReturnTrue() { Assert.IsTrue(viewModel.InitAsync().Result); var stub = new StubIChartUtil(MockBehavior.Strict); viewModel.ChartDao = stub; for (int i = 0; i < 4; i++) { viewModel.Infos.SelectSites.Add(new SelectSite() { IsSelected = true }); } stub.ChartLengendAsync(async(sites) => { ObservableCollection <ChartLengend> s = new ObservableCollection <ChartLengend>(); await Task.CompletedTask; return(s); }, Times.Twice); stub.CacuChartAsync(async(sites, logs) => { ObservableCollection <ObservableCollection <Chart1> > data1 = new ObservableCollection <ObservableCollection <Chart1> >(); ObservableCollection <BarChartData> data2 = new ObservableCollection <BarChartData>(); await Task.CompletedTask; return(new Tuple <ObservableCollection <ObservableCollection <Chart1> >, ObservableCollection <BarChartData> >(data1, data2)); }, Times.Twice); viewModel.Type = "All"; //less Assert.IsTrue(viewModel.AcceptClickAsync().Result); //equal viewModel.Infos.SelectSites.Add(new SelectSite() { IsSelected = true }); Assert.IsTrue(viewModel.AcceptClickAsync().Result); }