Beispiel #1
0
        public async Task UpdateNote()
        {
            var methodologyVersion = new MethodologyVersion
            {
                Id = Guid.NewGuid()
            };

            var methodologyNote = new MethodologyNote
            {
                Id = Guid.NewGuid(),
                MethodologyVersion = methodologyVersion
            };

            var persistenceHelper = new Mock <IPersistenceHelper <ContentDbContext> >(Strict);

            SetupCall(persistenceHelper, methodologyNote);

            await PolicyCheckBuilder <SecurityPolicies>()
            .SetupResourceCheckToFail(methodologyVersion, CanUpdateSpecificMethodology)
            .AssertForbidden(
                userService =>
            {
                var service = SetupMethodologyNoteService(
                    persistenceHelper: persistenceHelper.Object,
                    userService: userService.Object);
                return(service.UpdateNote(
                           methodologyVersion.Id,
                           methodologyNote.Id,
                           new MethodologyNoteUpdateRequest()));
            }
                );
        }
Beispiel #2
0
        public async Task UpdateNote()
        {
            var methodologyNote = new MethodologyNote
            {
                Content = "Original note",
                Created = DateTime.UtcNow,
                CreatedById = Guid.NewGuid(),
                DisplayDate = DateTime.Today.ToUniversalTime(),
                MethodologyVersion = new MethodologyVersion()
            };

            const string content = "Updating note";
            var updatedById = Guid.NewGuid();
            var displayDate = DateTime.Today.AddDays(-7).ToUniversalTime();

            var contentDbContextId = Guid.NewGuid().ToString();

            await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId))
            {
                await contentDbContext.MethodologyNotes.AddAsync(methodologyNote);
                await contentDbContext.SaveChangesAsync();
            }

            await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId))
            {
                var service = BuildMethodologyNoteRepository(contentDbContext);

                var result = await service.UpdateNote(
                    methodologyNoteId: methodologyNote.Id,
                    updatedByUserId: updatedById,
                    content: content,
                    displayDate: displayDate);

                Assert.NotNull(result);
            }

            await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId))
            {
                Assert.Single(contentDbContext.MethodologyNotes);

                var updatedNote = await contentDbContext.MethodologyNotes.SingleAsync(n => n.Id == methodologyNote.Id);

                Assert.Equal(content, updatedNote.Content);
                Assert.Equal(methodologyNote.Created, updatedNote.Created);
                Assert.Equal(methodologyNote.CreatedById, updatedNote.CreatedById);
                Assert.Equal(displayDate, updatedNote.DisplayDate);
                Assert.Equal(methodologyNote.MethodologyVersion.Id, updatedNote.MethodologyVersionId);
                Assert.NotNull(updatedNote.Updated);
                Assert.InRange(DateTime.UtcNow.Subtract(updatedNote.Updated!.Value).Milliseconds, 0, 1500);
                Assert.Equal(updatedById, updatedNote.UpdatedById);
            }
        }
Beispiel #3
0
        private static void AssertMethodologyNoteAmendedCorrectly(
            MethodologyNote amendmentNote,
            MethodologyNote originalNote,
            MethodologyVersion amendment)
        {
            // Check the note has a new id.
            Assert.NotEqual(Guid.Empty, amendmentNote.Id);
            Assert.NotEqual(originalNote.Id, amendmentNote.Id);

            // Check the note has the amended methodology version
            Assert.Equal(amendment, amendmentNote.MethodologyVersion);
            Assert.Equal(amendment.Id, amendmentNote.MethodologyVersionId);

            // Check the other fields are the same
            Assert.Equal(originalNote.Content, amendmentNote.Content);
            Assert.Equal(originalNote.Created, amendmentNote.Created);
            Assert.Equal(originalNote.CreatedBy, amendmentNote.CreatedBy);
            Assert.Equal(originalNote.CreatedById, amendmentNote.CreatedById);
            Assert.Equal(originalNote.DisplayDate, amendmentNote.DisplayDate);
            Assert.Equal(originalNote.Updated, amendmentNote.Updated);
            Assert.Equal(originalNote.UpdatedBy, amendmentNote.UpdatedBy);
            Assert.Equal(originalNote.UpdatedById, amendmentNote.UpdatedById);
        }
Beispiel #4
0
 private MethodologyNoteViewModel BuildMethodologyNoteViewModel(MethodologyNote methodologyNote)
 {
     return(_mapper.Map <MethodologyNoteViewModel>(methodologyNote));
 }