Exemplo n.º 1
0
        public void When_Old_Version_Does_Not_Have_New_Values_They_Are_Recorded_And_No_Audit_Created()
        {
            // arrange
            var       justNow         = DateTime.UtcNow.AddSeconds(-1);
            ReportDto actualReportDto = null;
            var       reportId        = Guid.NewGuid();
            var       updateUser      = new User {
                Id = Guid.NewGuid(), Name = "Homer"
            };

            var oldVersion = new ReportDto
            {
                Id = reportId,
                AuditWindowStartUtc = null,
                UpdatedUtc          = null,
                UpdatedBy           = null,
                ReportingData       = "old report"
            };

            var newVersion = new ReportDto
            {
                Id = reportId,
                AuditWindowStartUtc = null,
                UpdatedUtc          = null,
                UpdatedBy           = null,
                ReportingData       = "new report"
            };

            _reportRepositoryMock.Setup(s => s.Get(reportId)).Returns(oldVersion).Verifiable();
            _reportRepositoryMock.Setup(s => s.Update(It.IsAny <ReportDto>())).Callback <ReportDto>(d => actualReportDto = d).Verifiable();
            _mapperMock.Setup(s => s.Map <ReportDto>(It.IsAny <Report>())).Returns(newVersion);

            var updateReportRequest =
                new UpdateReportRequestBuilder()
                .WithUserName(updateUser.Name)
                .WithUserId(updateUser.Id)
                .WithAutoWindowSizeInMinutes(5)
                .WithReport(
                    new Report
            {
                Id = reportId,
                AuditWindowStartUtc = null,
                UpdatedUtc          = null,
                UpdatedBy           = null
            })
                .Build();

            // act
            _updateReportHandler.Handle(updateReportRequest, default(CancellationToken));

            // assert
            _reportRepositoryMock.VerifyAll();

            Assert.IsNotNull(actualReportDto);
            Assert.IsNotNull(actualReportDto.AuditWindowStartUtc);
            Assert.IsNotNull(actualReportDto.UpdatedUtc);
            Assert.IsNotNull(actualReportDto.UpdatedBy);
            Assert.IsTrue(actualReportDto.UpdatedBy.Contains(updateUser.Name));
            Assert.AreEqual(newVersion.ReportingData, actualReportDto.ReportingData);
        }
Exemplo n.º 2
0
        public void When_Report_Is_Updated_Less_Than_Audit_Window_Size_Ago_Then_Audit_Record_Is_Not_Created()
        {
            // arrange
            var       justNow         = DateTime.UtcNow;
            ReportDto actualReportDto = null;
            var       reportId        = Guid.NewGuid();
            var       updateUser      = new User {
                Id = Guid.NewGuid(), Name = "Homer"
            };
            var oldVersion = new ReportDto
            {
                Id = reportId,
                AuditWindowStartUtc = justNow,
                UpdatedUtc          = justNow,
                UpdatedBy           = $"{{ Id: '{updateUser.Id}', Name: '{updateUser.Name}' }}"
            };
            var newVersion = new ReportDto
            {
                Id = reportId,
                AuditWindowStartUtc = justNow,
                UpdatedUtc          = justNow,
                UpdatedBy           = $"{{ Id: '{updateUser.Id}', Name: '{updateUser.Name}' }}"
            };

            _reportRepositoryMock.Setup(s => s.Get(reportId)).Returns(oldVersion).Verifiable();
            _reportRepositoryMock.Setup(s => s.Update(It.IsAny <ReportDto>())).Callback <ReportDto>(d => actualReportDto = d).Verifiable();
            _mapperMock.Setup(s => s.Map <ReportDto>(It.IsAny <Report>())).Returns(newVersion);

            var updateReportRequest =
                new UpdateReportRequestBuilder()
                .WithUserName(updateUser.Name)
                .WithUserId(updateUser.Id)
                .WithAutoWindowSizeInMinutes(5)
                .WithReport(
                    new Report
            {
                Id = reportId,
                AuditWindowStartUtc = justNow,
                UpdatedUtc          = justNow,
                UpdatedBy           = new User {
                    Id = Guid.Empty, Name = "Homer"
                }
            })
                .Build();

            // act
            _updateReportHandler.Handle(updateReportRequest, default(CancellationToken));

            // assert
            _reportRepositoryMock.VerifyAll();
            Assert.IsNotNull(actualReportDto);
            Assert.AreEqual(justNow, actualReportDto.AuditWindowStartUtc);
            Assert.AreNotEqual(justNow, actualReportDto.UpdatedUtc);
            Assert.IsNotNull(actualReportDto.UpdatedBy);
            Assert.IsTrue(actualReportDto.UpdatedBy.Contains(updateUser.Name));
        }
Exemplo n.º 3
0
        public void When_Old_Version_Cannot_Be_Found_Then_Throw_Error()
        {
            // arrange
            var reportId            = Guid.NewGuid();
            var updateReportRequest =
                new UpdateReportRequestBuilder()
                .WithUserName("Bob Shurunkle")
                .WithReport(
                    new Report {
                Id = reportId
            })
                .Build();

            _reportRepositoryMock.Setup(s => s.Get(reportId)).Returns((ReportDto)null).Verifiable();

            // act
            // assert
            Assert.Throws <Exception>(() => _updateReportHandler.Handle(updateReportRequest, new CancellationToken()));
        }