public void AddMock() { var testMock = new Mock <ITestCollectionService>(); var mapper = new Mock <IMapper>(); TestItem amanda = new TestItem() { Key = "ano.nascimento", SubIndex = 1983, Value = "amanda" }; TestItemViewModel amandaViewModel = new TestItemViewModel() { Key = "ano.nascimento", SubIndex = 1983, Value = "amanda" }; TestItem caio = new TestItem() { Key = "ano.nascimento", SubIndex = 1983, Value = "caio" }; TestItemViewModel caioViewModel = new TestItemViewModel() { Key = "ano.nascimento", SubIndex = 1983, Value = "caio" }; testMock.Setup(x => x.Add(amanda)).Returns(true); testMock.Setup(x => x.Add(caio)).Returns(false); mapper.Setup(x => x.Map <TestItem>(amandaViewModel)).Returns(amanda); mapper.Setup(x => x.Map <TestItem>(caioViewModel)).Returns(caio); ITestCollectionAppService testCollectionAppService = new TestCollectionAppService(testMock.Object, mapper.Object); Assert.IsTrue(testCollectionAppService.Add(amandaViewModel)); Assert.IsFalse(testCollectionAppService.Add(caioViewModel)); }
public static KeyValuePair <TestItem, TestItemViewModel> ExistingDestCollEqualsWithNullElement() { var testItem = new TestItem(); var testItemVm = new TestItemViewModel(); var testItems = new List <TestCollection>(); var testItemsVm = new List <TestCollectionViewModel>(); for (var i = 0; i < 5; i++) { var id = Guid.NewGuid(); var format = string.Format("Name - {0}", i); var name = string.Format("{0} - CHANGED!", format); var testCollection = new TestCollection { Id = id, Name = name }; var testCollectionVm = new TestCollectionViewModel { Id = id, Name = format }; testItems.Add(testCollection); testItemsVm.Add(i == 3 ? null : testCollectionVm); } testItem.Queryable = testItems.AsQueryable(); testItemVm.Array = testItemsVm.ToArray(); return(new KeyValuePair <TestItem, TestItemViewModel>(testItem, testItemVm)); }
public bool Add(TestItemViewModel item) { try { return(_testCollectionService.Add(_mapper.Map <TestItem>(item))); } catch (Exception ex) { throw ex; } }
public IActionResult Post([FromBody] TestItemViewModel item) { try { return(Ok(_testCollectionAppService.Add(item))); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public void ConstructorItemViewModel() { // arrange var model = new Model { Text = "test" }; // act var vm = new TestItemViewModel(model); // assert Assert.Equal(model, vm.Item); }
public static KeyValuePair <TestItem, TestItemViewModel> CollectionTypeMap() { var random = new Random(); var next = random.Next(5, 10); var testCollections = new List <TestCollection>(); var testCollectionViewModels = new List <TestCollectionViewModel>(); for (var i = 0; i < next; i++) { var newGuid = Guid.NewGuid(); testCollections.Add(new TestCollection { Id = newGuid, Name = string.Format("Name - {0}", i) }); testCollectionViewModels.Add(new TestCollectionViewModel { Id = newGuid, Name = string.Format("Name - {0}", i) }); } var testItem = new TestItem { Array = testCollections.ToArray(), Collection = testCollections, Enumerable = testCollections, List = testCollections, Queryable = testCollections.AsQueryable() }; var testItemViewModel = new TestItemViewModel { Array = testCollectionViewModels.ToArray(), Collection = testCollectionViewModels, Enumerable = testCollectionViewModels, List = testCollectionViewModels, Queryable = testCollectionViewModels.AsQueryable() }; var keyValuePair = new KeyValuePair <TestItem, TestItemViewModel>(testItem, testItemViewModel); return(keyValuePair); }
public void SetItemWithNotification() { // arrange var vm = new TestItemViewModel(); var model = new Model { Text = "test" }; bool propertyFired = false; vm.PropertyChanged += (sender, e) => { if (e.PropertyName == "Item") { propertyFired = true; } }; // act vm.Item = model; // assert Assert.True(propertyFired); }
private void AddTestAnchorAdornment(ITextViewLine line, SnapshotSpan span, TestItemViewModel viewModel, bool isUpToDate) { if (viewModel == null) { return; } var viewBox = new Viewbox() { Width = _textView.LineHeight, Height = _textView.LineHeight, Stretch = Stretch.Uniform }; var button = new ActionButton() { DataContext = viewModel, Opacity = isUpToDate ? 1 : _modifiedOpacity, CommandParameter = viewModel.CodeItem, Command = _selectTestCommand, Cursor = Cursors.Hand, Tag = new AnchorData() { Targets = new TestMethod[] { viewModel.CodeItem as TestMethod }, Type = AnchorType.Test } }; button.SetBinding(ActionButton.IconProperty, new Binding(nameof(viewModel.IconPath))); button.MouseRightButtonDown += (o, e) => e.Handled = true; button.MouseRightButtonUp += OnTestItemRightButtonUp; viewBox.Child = button; Canvas.SetLeft(viewBox, _sequenceCoverageLineWidth); Canvas.SetTop(viewBox, line.Top); _adornmentLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, viewBox, null); }
public static KeyValuePair <TestItem, TestItemViewModel> ExistingDestCollNotEqual() { var testItem = new TestItem(); var testItemVm = new TestItemViewModel(); var testItems = new List <TestCollection>(); var testItemsVm = new List <TestCollectionViewModel>(); for (var i = 0; i < 10; i++) { var id = Guid.NewGuid(); var format = string.Format("Name - {0}", i); var name = string.Format("{0} - CHANGED!", format); var testCollection = new TestCollection { Id = id, Name = name }; var testCollectionVm = new TestCollectionViewModel { Id = id, Name = format }; if (i < 6) { testItems.Add(testCollection); } testItemsVm.Add(testCollectionVm); } testItem.Collection = testItems; testItemVm.Array = testItemsVm.ToArray(); return(new KeyValuePair <TestItem, TestItemViewModel>(testItem, testItemVm)); }