public async void AddWidgetToAreaAsync_adds_widget_to_widget_area() { // Arrange Setup_MyWidget(); Setup_Widget_Areas(); // Act: user drags MyWidget to "my-area" // NOTE: area id is "my-area" not its meta key which is "mytheme-my-area" var widgetInst = await widgetService.AddWidgetToAreaAsync(MY_WIDGET_ID, MY_AREA_ID, index : 0); // Assert: repo UpdateAsync is called twice metaRepoMock.Verify(repo => repo.UpdateAsync(It.IsAny <Meta>()), Times.Exactly(2)); // Once: update widget instance with widget id and widget area id var myWidget = new MyWidget { Id = MY_WIDGET_ID, AreaId = MY_AREA_ID, Folder = MY_WIDGET_FOLDER }; metaRepoMock.Verify(repo => repo.UpdateAsync( It.Is <Meta>(m => m.Value == JsonConvert.SerializeObject(myWidget))), Times.Once); // Once: update widget area "my-area" with MyWidget of id 4 var myArea = new WidgetArea { Id = MY_AREA_ID, WidgetIds = new int[] { MY_WIDGET_ID } }; metaRepoMock.Verify(repo => repo.UpdateAsync( It.Is <Meta>(m => m.Value == JsonConvert.SerializeObject(myArea))), Times.Once); Assert.Equal(MY_WIDGET_ID, widgetInst.Id); Assert.Equal(MY_WIDGET_FOLDER, widgetInst.Folder); Assert.Equal(MY_AREA_ID, widgetInst.AreaId); Assert.Equal("My Widget", widgetInst.Title); Assert.Equal("/Widgets/MyWidgetSettings?widgetId=4", widgetInst.SettingsUrl); }
private void Setup_MyWidget() { var myWidget = new MyWidget { Folder = MY_WIDGET_FOLDER }; var meta = new Meta { Id = MY_WIDGET_ID, Key = "mywidget-2da0l8", Value = JsonConvert.SerializeObject(myWidget), Type = EMetaType.Widget, }; metaRepoMock.Setup(repo => repo.GetAsync(MY_WIDGET_ID)).Returns(Task.FromResult(meta)); }
public async void UpdateWidgetAsync_updates_meta_for_widget() { // Arrange: myWidget meta var myWidget = new MyWidget { Folder = MY_WIDGET_FOLDER }; var myWidgetMetaValueAfterCreate = JsonConvert.SerializeObject(myWidget); var meta = new Meta { Id = MY_WIDGET_ID, Key = MY_AREA_META_KEY, Value = myWidgetMetaValueAfterCreate, Type = EMetaType.WidgetAreaByTheme }; metaRepoMock.Setup(repo => repo.GetAsync(MY_WIDGET_ID)).Returns(Task.FromResult(meta)); // Act: user saves myWidget settings await widgetService.UpdateWidgetAsync(MY_WIDGET_ID, myWidget); // Assert: repo UpdateAsync is called once metaRepoMock.Verify(repo => repo.UpdateAsync(It.Is <Meta>(m => m.Value == myWidgetMetaValueAfterCreate)), Times.Once); }
public async void CreateWidgetAsync_creates_a_meta_for_widget() { // Arrange: 3 widget areas including my-area Setup_Widget_Areas_for_create(); // Given myWidget with id 0 var myWidget = new MyWidget { Id = 0, AreaId = null, Folder = MY_WIDGET_FOLDER }; var myWidgetMetaValueAfterCreate = JsonConvert.SerializeObject(myWidget); var meta = new Meta { Id = MY_WIDGET_ID, Key = MY_AREA_META_KEY, Value = myWidgetMetaValueAfterCreate, Type = EMetaType.WidgetAreaByTheme }; metaRepoMock.Setup(repo => repo.CreateAsync(It.Is <Meta>(m => m.Value == myWidgetMetaValueAfterCreate))) .Returns(Task.FromResult(meta)); // Act: when a user drops a widget into an area the first step is to create the widget var id = await widgetService.CreateWidgetAsync(MY_WIDGET_FOLDER); // Assert: CreateAsync creates an instance of MyWidget with an Id of 0 metaRepoMock.Verify(repo => repo.CreateAsync(It.Is <Meta>(m => m.Value == myWidgetMetaValueAfterCreate)), Times.Once); Assert.Equal(MY_WIDGET_ID, id); }