public async Task ShouldFailSubmitingData() { _MockSubmissionService.Setup(p => p.SubmitTotalArea(It.IsAny <double>())).Throws(new Exception()); var viewModel = new ShapesViewModel(_MockShapesRepository.Object, _MockComputeAreaService.Object, _MockSubmissionService.Object); await viewModel.SubmitAreaAsync(); _MockSubmissionService.Verify(p => p.SubmitTotalArea(It.IsAny <double>())); viewModel.SubmissionResult.Should().Be(SubmissionResult.Failure); viewModel.SubmissionInProgress.Should().Be(false); viewModel.SubmitAreaCommand.CanExecute().Should().Be(true); }
public void ShoudShowAddNewShapeWindow() { var expectedCalledType = typeof(AddShapeViewModel); var viewModel = new ShapesViewModel(_MockShapesRepository.Object, _MockComputeAreaService.Object, _MockSubmissionService.Object); Type calledType = null; TestSetup.Setup(); TestSetup.MvxViewDispatcher.Setup(p => p.ShowViewModel(It.IsAny <MvxViewModelRequest>())).Callback <MvxViewModelRequest>(request => calledType = request.ViewModelType); viewModel.AddShapeCommand.Execute(null); TestSetup.MvxViewDispatcher.Verify(p => p.ShowViewModel(It.IsAny <MvxViewModelRequest>())); calledType.Should().Be(expectedCalledType); }
public void ShouldAddShapeToShapesWhenShapeIsAddedToRepo() { const int expectedCount = 2; var shapes = new List <IShape>() { new Square { SideLength = 2 } }; _MockShapesRepository.Setup(p => p.GetShapes()).Returns(shapes); var viewModel = new ShapesViewModel(_MockShapesRepository.Object, _MockComputeAreaService.Object, _MockSubmissionService.Object); viewModel.Start(); _MockShapesRepository.Raise(repository => repository.ShapeAdded += null, new ShapeEventArgs(new Circle())); viewModel.Shapes.Count.Should().Be(expectedCount); }
public void ShoudComputeTotalArea() { const double expectedTotalArea = 4d; var shapes = new List <IShape>() { new Square { SideLength = 2 } }; _MockShapesRepository.Setup(p => p.GetShapes()).Returns(shapes); _MockComputeAreaService.Setup(p => p.ComputeTotalArea()).Returns(expectedTotalArea); var viewModel = new ShapesViewModel(_MockShapesRepository.Object, _MockComputeAreaService.Object, _MockSubmissionService.Object); viewModel.TotalArea.Should().BeApproximately(0, precision); viewModel.ComputeAreaCommand.Execute(null); viewModel.TotalArea.Should().BeApproximately(expectedTotalArea, precision); }