public void シナリオ() { var weatherMock = new Mock <IWeatherRepository>(); weatherMock.Setup(x => x.GetLatest(1)).Returns( new WeatherEntity( 1, Convert.ToDateTime("2018/01/01 12:24:56"), 2, 12.3f)); weatherMock.Setup(x => x.GetLatest(2)).Returns( new WeatherEntity( 2, Convert.ToDateTime("2018/01/02 12:24:56"), 1, 22.123f)); var areasMock = new Mock <IAreasRepository>(); var areas = new List <AreaEntity>(); areas.Add(new AreaEntity(1, "東京")); areas.Add(new AreaEntity(2, "神戸")); areas.Add(new AreaEntity(3, "沖縄")); areasMock.Setup(x => x.GetData()).Returns(areas); var viewModel = new WeatherLatestViewModel(weatherMock.Object, areasMock.Object); Assert.IsNull(viewModel.SelectedAreaId); Assert.AreEqual("", viewModel.DataDateText); Assert.AreEqual("", viewModel.ConditionText); Assert.AreEqual("", viewModel.TemperatureText); Assert.AreEqual(3, viewModel.Areas.Count); Assert.AreEqual(1, viewModel.Areas[0].AreaId); Assert.AreEqual("東京", viewModel.Areas[0].AreaName); Assert.AreEqual(2, viewModel.Areas[1].AreaId); Assert.AreEqual("神戸", viewModel.Areas[1].AreaName); viewModel.SelectedAreaId = 1; viewModel.Search(); Assert.AreEqual(1, viewModel.SelectedAreaId); Assert.AreEqual("2018/01/01 12:24:56", viewModel.DataDateText); Assert.AreEqual("曇り", viewModel.ConditionText); Assert.AreEqual("12.30 ℃", viewModel.TemperatureText); viewModel.SelectedAreaId = 2; viewModel.Search(); Assert.AreEqual(2, viewModel.SelectedAreaId); Assert.AreEqual("2018/01/02 12:24:56", viewModel.DataDateText); Assert.AreEqual("晴れ", viewModel.ConditionText); Assert.AreEqual("22.12 ℃", viewModel.TemperatureText); viewModel.SelectedAreaId = 3; viewModel.Search(); Assert.AreEqual(3, viewModel.SelectedAreaId); Assert.AreEqual("", viewModel.DataDateText); Assert.AreEqual("", viewModel.ConditionText); Assert.AreEqual("", viewModel.TemperatureText); }
public void シナリオ() { var watherMoc = new Mock <IWeatherRepository>(); watherMoc.Setup(x => x.GetLatest(1)) .Returns(new WeatherEntity( 1, Convert.ToDateTime("2018/01/01 12:34:56"), 2, 12.3f)); //watherMoc.Setup(x => x.GetLatest(2)) // .Returns(new WeatherEntity( // 2, // Convert.ToDateTime("2019/05/01 0:00:00"), // 1, // 24.23f)); var areas = new List <AreaEntity>(); areas.Add(new AreaEntity(1, "東京")); //areas.Add(new AreaEntity(2, "神戸")); areas.Add(new AreaEntity(3, "沖縄")); var areasMock = new Mock <IAreasRepository>(); areasMock.Setup(x => x.GetData()).Returns(areas); //Objectの中にwatherMocのインスタンスがある var viewModel = new WeatherLatestViewModel( watherMoc.Object, areasMock.Object ); //var viewModel = new WeatherLatestViewModel(new WeatherMock()); Assert.IsNull(viewModel.SelectedAreaId); Assert.AreEqual("", viewModel.DataDateText); Assert.AreEqual("", viewModel.ConditionText); Assert.AreEqual("", viewModel.TemperatureText); //Assert.AreEqual(2, viewModel.Areas.Count); Assert.AreEqual(1, viewModel.Areas[0].AreaId); Assert.AreEqual("東京", viewModel.Areas[0].AreaName); viewModel.SelectedAreaId = 1; viewModel.Search(); Assert.AreEqual(1, viewModel.SelectedAreaId); Assert.AreEqual("2018/01/01 12:34:56", viewModel.DataDateText); Assert.AreEqual("曇り", viewModel.ConditionText); Assert.AreEqual("12.30 ℃", viewModel.TemperatureText); viewModel.SelectedAreaId = 3; viewModel.Search(); Assert.AreEqual(3, viewModel.SelectedAreaId); Assert.AreEqual("", viewModel.DataDateText); Assert.AreEqual("", viewModel.ConditionText); Assert.AreEqual("", viewModel.TemperatureText); }
public void 表示シナリオ() { var weatherMock = new Mock <IWeatherRepository>(); var areasMock = new Mock <IAreasRepository>(); var areas = new List <AreaEntity>(); areas.Add(new AreaEntity(1, "東京")); areas.Add(new AreaEntity(2, "神戸")); areas.Add(new AreaEntity(3, "沖縄")); areasMock.Setup(x => x.GetData()).Returns(areas); var viewModel = new WeatherLatestViewModel(weatherMock.Object, areasMock.Object); viewModel.selectedAreaId.IsNull(); viewModel.DataDateText.Is(""); viewModel.ConditionText.Is(""); viewModel.TemperatureText.Is(""); viewModel.Areas.Count.Is(3); viewModel.Areas[0].AreaId.Is(1); viewModel.Areas[0].AreaName.Is("東京"); viewModel.Areas[1].AreaId.Is(2); viewModel.Areas[1].AreaName.Is("神戸"); viewModel.selectedAreaId = 1; weatherMock.Setup(x => x.GetLatest(1)) .Returns(new WeatherEntity( 1, Convert.ToDateTime("2020/01/01 12:34:56"), 2, 12.3F)); viewModel.Search(); viewModel.selectedAreaId.Is(1); viewModel.DataDateText.Is("2020/01/01 12:34:56");; viewModel.ConditionText.Is("曇り"); viewModel.TemperatureText.Is("12.30 ℃"); viewModel.selectedAreaId = 2; weatherMock.Setup(x => x.GetLatest(2)) .Returns(new WeatherEntity( 2, Convert.ToDateTime("2020/01/01 12:34:56"), 1, 22.1345F)); viewModel.Search(); viewModel.selectedAreaId.Is(2); viewModel.DataDateText.Is("2020/01/01 12:34:56");; viewModel.ConditionText.Is("晴れ"); viewModel.TemperatureText.Is("22.13 ℃"); viewModel.selectedAreaId = 3; viewModel.Search(); viewModel.selectedAreaId.Is(3); viewModel.DataDateText.Is("");; viewModel.ConditionText.Is(""); viewModel.TemperatureText.Is(""); }
public void データベース接続に関する値の確認() { var viewModel = new WeatherLatestViewModel(new WeatherMock()); Assert.AreEqual("", viewModel.AreaIdText); Assert.AreEqual("", viewModel.DataDateText); Assert.AreEqual("", viewModel.ConditionText); Assert.AreEqual("", viewModel.TemperatureText); viewModel.AreaIdText = "1"; viewModel.Search(); Assert.AreEqual("1", viewModel.AreaIdText); Assert.AreEqual("2018/01/01 12:34:56", viewModel.DataDateText); Assert.AreEqual("2", viewModel.ConditionText); Assert.AreEqual("12.30 ℃", viewModel.TemperatureText); }
public void シナリオ() { var weatherMock = new Mock <IWeatherRepository>(); weatherMock.Setup(x => x.GetLatest(1)).Returns( new WeatherEntity( 1, Convert.ToDateTime("2018/01/01 12:34:56"), 2, 12.3f)); var areas = new List <AreaEntity>(); areas.Add(new AreaEntity(1, "東京")); areas.Add(new AreaEntity(2, "神戸")); areas.Add(new AreaEntity(3, "沖縄")); var areaMock = new Mock <IAreaRepository>(); areaMock.Setup(x => x.Getdata()).Returns(areas); //初期値 var viewModel = new WeatherLatestViewModel(weatherMock.Object, areaMock.Object); Assert.IsNull(viewModel.SelectedAreaID); Assert.AreEqual("", viewModel.DataDateText); Assert.AreEqual("", viewModel.ConditionText); Assert.AreEqual("", viewModel.TempartureText); Assert.AreEqual(3, viewModel.Areas.Count); //直近値をもってくる viewModel.SelectedAreaID = 1; viewModel.Search(); Assert.AreEqual(1, viewModel.SelectedAreaID); Assert.AreEqual("2018/01/01 12:34:56", viewModel.DataDateText); Assert.AreEqual("曇り", viewModel.ConditionText); Assert.AreEqual("12.30 ℃", viewModel.TempartureText); //直近値をもってくる viewModel.SelectedAreaID = 3; viewModel.Search(); Assert.AreEqual(3, viewModel.SelectedAreaID); Assert.AreEqual("", viewModel.DataDateText); Assert.AreEqual("", viewModel.ConditionText); Assert.AreEqual("", viewModel.TempartureText); }
public void TestMethod1() { //起動初期値 var WeatherMock = new Mock <IWeatherRepository>(); var vm = new WeatherLatestViewModel(WeatherMock.Object); vm.AreaIdText.Is(""); vm.AreaNameText.Is(""); vm.DataDateText.Is(""); vm.ConditionText.Is(""); vm.TemperatureText.Is(""); var entiry = new WeatherEntity(1, "東京", Convert.ToDateTime("2021/01/02 11:22:33"), 1, 20.302F); WeatherMock.Setup(x => x.GetLatest()).Returns(entiry); vm.Search(); vm.AreaIdText.Is("1"); vm.AreaNameText.Is("東京"); vm.DataDateText.Is("2021/01/02 11:22:33"); vm.ConditionText.Is("1"); vm.TemperatureText.Is("20.30 ℃"); }