public void ApplyChangesAndNotifyAsync_WhenDateIsSet_UpdateValue_LogInGroupHistory() { var group = new Group { Data = GroupDataJson, Id = GroupId }; var groupData = new GroupData(); var groupHistoryEntry = new GroupHistoryEntry(); var request = new PatchGroupRequest { Date = new NhbkDateRequest() { Day = 8 } }; _groupHistoryUtil.CreateLogChangeDate(group, Arg.Any <NhbkDate>(), Arg.Any <NhbkDate>()) .Returns(groupHistoryEntry); _jsonUtil.Deserialize <GroupData>(GroupDataJson) .Returns(groupData); _jsonUtil.Serialize(groupData) .Returns(UpdatedGroupDataJson); _util.ApplyChangesAndNotify(group, request, _notificationSession); group.Data.Should().BeEquivalentTo(UpdatedGroupDataJson); groupData.Date.Day.Should().Be(8); group.HistoryEntries.Should().Contain(groupHistoryEntry); }
public void ApplyChangesAndNotifyAsync_WhenDebilibeukIsSet_UpdateValue_LogInGroupHistory() { var group = new Group { Data = GroupDataJson, Id = GroupId }; var groupData = new GroupData(); var groupHistoryEntry = new GroupHistoryEntry(); var request = new PatchGroupRequest { Debilibeuk = 4 }; _groupHistoryUtil.CreateLogChangeDebilibeuk(group, null, 4) .Returns(groupHistoryEntry); _jsonUtil.Deserialize <GroupData>(GroupDataJson) .Returns(groupData); _jsonUtil.Serialize(groupData) .Returns(UpdatedGroupDataJson); _util.ApplyChangesAndNotify(group, request, _notificationSession); group.Data.Should().BeEquivalentTo(UpdatedGroupDataJson); groupData.Debilibeuk.Should().Be(4); group.HistoryEntries.Should().Contain(groupHistoryEntry); }
public void PatchGroupAsync_ShouldReturnExpectedHttpStatusCodeOnKnownErrors(Exception exception, int expectedStatusCode) { const int groupId = 8; var request = new PatchGroupRequest(); _groupService.EditGroupPropertiesAsync(_executionContext, groupId, request) .Returns(Task.FromException <List <Loot> >(exception)); Func <Task> act = () => _controller.PatchGroupAsync(_executionContext, groupId, request); act.Should().Throw <HttpErrorException>().Which.StatusCode.Should().Be(expectedStatusCode); }
public async Task EditGroupPropertiesAsync_ShouldApplyChangeOnGroupThenSave() { const int groupId = 4; var naheulbookExecutionContext = new NaheulbookExecutionContext(); var request = new PatchGroupRequest(); var group = new Group(); _unitOfWorkFactory.GetUnitOfWork().Groups.GetAsync(groupId) .Returns(group); await _service.EditGroupPropertiesAsync(naheulbookExecutionContext, groupId, request); Received.InOrder(() => { _groupUtil.ApplyChangesAndNotify(group, request, _notificationSessionFactory.NotificationSession); _unitOfWorkFactory.GetUnitOfWork().SaveChangesAsync(); _notificationSessionFactory.NotificationSession.CommitAsync(); }); }
public async Task <IActionResult> PatchGroupAsync( [FromServices] NaheulbookExecutionContext executionContext, [FromRoute] int groupId, PatchGroupRequest request ) { try { await _groupService.EditGroupPropertiesAsync(executionContext, groupId, request); return(NoContent()); } catch (ForbiddenAccessException ex) { throw new HttpErrorException(StatusCodes.Status403Forbidden, ex); } catch (GroupNotFoundException ex) { throw new HttpErrorException(StatusCodes.Status404NotFound, ex); } }
public void ApplyChangesAndNotify(Group group, PatchGroupRequest request, INotificationSession notificationSession) { var groupData = _jsonUtil.Deserialize <GroupData>(group.Data) ?? new GroupData(); if (request.Mankdebol.HasValue) { group.AddHistoryEntry(_groupHistoryUtil.CreateLogChangeMankdebol(group, groupData.Mankdebol, request.Mankdebol.Value)); groupData.Mankdebol = request.Mankdebol.Value; } if (request.Debilibeuk.HasValue) { group.AddHistoryEntry(_groupHistoryUtil.CreateLogChangeDebilibeuk(group, groupData.Debilibeuk, request.Debilibeuk.Value)); groupData.Debilibeuk = request.Debilibeuk.Value; } if (request.Date != null) { var newDate = new NhbkDate(request.Date); group.AddHistoryEntry(_groupHistoryUtil.CreateLogChangeDate(group, groupData.Date, newDate)); groupData.Date = newDate; } if (request.FighterIndex != null) { groupData.CurrentFighterIndex = request.FighterIndex.Value; } if (request.Name != null) { group.Name = request.Name; } notificationSession.NotifyGroupChangeGroupData(group.Id, groupData); group.Data = _jsonUtil.Serialize(groupData); }
public async Task EditGroupPropertiesAsync(NaheulbookExecutionContext executionContext, int groupId, PatchGroupRequest request) { var notificationSession = _notificationSessionFactory.CreateSession(); using (var uow = _unitOfWorkFactory.CreateUnitOfWork()) { var group = await uow.Groups.GetAsync(groupId); if (group == null) { throw new GroupNotFoundException(groupId); } _authorizationUtil.EnsureIsGroupOwner(executionContext, group); _groupUtil.ApplyChangesAndNotify(group, request, notificationSession); await uow.SaveChangesAsync(); } await notificationSession.CommitAsync(); }