Esempio n. 1
0
        public void Setup()
        {
            _projectRepositoryMock = new Mock <IProjectRepository>();

            var tagId   = 2;
            var tagMock = new Mock <Tag>();

            tagMock.SetupGet(t => t.Plant).Returns(TestPlant);
            tagMock.SetupGet(t => t.Id).Returns(tagId);
            var actionId = 12;

            _action = new Action(TestPlant, _oldTitle, _oldDescription, _oldDueTimeUtc);
            _action.SetProtectedIdForTesting(actionId);
            tagMock.Object.AddAction(_action);

            _projectRepositoryMock
            .Setup(r => r.GetTagByTagIdAsync(tagId))
            .Returns(Task.FromResult(tagMock.Object));

            _command = new UpdateActionCommand(tagId, actionId, _newTitle, _newDescription, _newDueTimeUtc, _rowVersion);

            _dut = new UpdateActionCommandHandler(
                _projectRepositoryMock.Object,
                UnitOfWorkMock.Object
                );
        }
        private static void SeedActionAttachment(PreservationContext dbContext, Action action)
        {
            var attachment = new ActionAttachment(action.Plant, KnownTestData.ActionAttachmentBlobStorageId, "Fil2.txt");

            action.AddAttachment(attachment);
            dbContext.SaveChangesAsync().Wait();
        }
Esempio n. 3
0
 private void AssertClosedAction(ActionDetailsDto actionDetailsDto, Action action, Person closer)
 {
     AssertAction(actionDetailsDto, action, true);
     Assert.AreEqual(closer.Id, actionDetailsDto.ClosedBy.Id);
     Assert.AreEqual(closer.FirstName, actionDetailsDto.ClosedBy.FirstName);
     Assert.AreEqual(closer.LastName, actionDetailsDto.ClosedBy.LastName);
 }
Esempio n. 4
0
        private (Project, Action) CreateAction(PreservationContext context, string projectName, bool closeProject)
        {
            var plantId = _plantProvider.Plant;
            var mode    = new Mode(plantId, "M1", false);

            context.Modes.Add(mode);

            var responsible = new Responsible(plantId, "Resp1", "Resp1-Desc");

            context.Responsibles.Add(responsible);
            context.SaveChangesAsync().Wait();

            var journey = new Journey(plantId, "J1");
            var step    = new Step(plantId, "S1", mode, responsible);

            journey.AddStep(step);
            context.Journeys.Add(journey);
            context.SaveChangesAsync().Wait();

            var requirementType = new RequirementType(plantId, "RT", "RT title", RequirementTypeIcon.Other, 1);

            context.RequirementTypes.Add(requirementType);

            var requirementDefinition = new RequirementDefinition(plantId, "RD", 2, RequirementUsage.ForAll, 1);

            requirementType.AddRequirementDefinition(requirementDefinition);
            context.SaveChangesAsync().Wait();

            var project = new Project(plantId, projectName, $"{projectName} Desc")
            {
                IsClosed = closeProject
            };

            context.Projects.Add(project);

            var tag = new Tag(
                plantId,
                TagType.Standard,
                "Tag A",
                "Tag desc",
                step,
                new List <TagRequirement> {
                new TagRequirement(plantId, 2, requirementDefinition)
            });

            project.AddTag(tag);
            context.SaveChangesAsync().Wait();

            var action = new Action(plantId, "A", "D", null);

            tag.AddAction(action);

            var attachment = new ActionAttachment(plantId, Guid.Empty, "fil.txt");

            action.AddAttachment(attachment);

            context.SaveChangesAsync().Wait();
            return(project, action);
        }
Esempio n. 5
0
 public void Setup()
 {
     _personMock = new Mock <Person>();
     _personMock.SetupGet(p => p.Id).Returns(PersonId);
     _utcNow       = new DateTime(2020, 1, 1, 1, 1, 1, DateTimeKind.Utc);
     _timeProvider = new ManualTimeProvider(_utcNow);
     TimeService.SetProvider(_timeProvider);
     _dut = new Action(TestPlant, "TitleA", "DescA", _utcNow);
 }
Esempio n. 6
0
 private void AssertAction(ActionDto actionDto, Action action)
 {
     Assert.AreEqual(action.Id, actionDto.Id);
     Assert.AreEqual(action.IsOverDue(), actionDto.IsOverDue);
     Assert.AreEqual(action.Title, actionDto.Title);
     Assert.AreEqual(action.IsClosed, actionDto.IsClosed);
     Assert.AreEqual(action.DueTimeUtc, actionDto.DueTimeUtc);
     Assert.AreEqual(action.Attachments.Count, actionDto.AttachmentCount);
 }
        private static Action SeedAction(PreservationContext dbContext, Tag tag)
        {
            var suffix = Guid.NewGuid().ToString().Substring(3, 8);
            var title  = $"{KnownTestData.Action}-{suffix}";
            var action = new Action(tag.Plant, title, $"{title}-Desc", new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc));

            tag.AddAction(action);
            dbContext.SaveChangesAsync().Wait();
            return(action);
        }
Esempio n. 8
0
        public void IsOverDue_ShouldBeFalseWhenDueDateExactNow()
        {
            // Arrange
            _dut = new Action(TestPlant, "TitleA", "DescA", _utcNow);

            // Act
            var overDue = _dut.IsOverDue();

            // Assert
            Assert.IsFalse(overDue);
        }
Esempio n. 9
0
 private static void AssertAction(ActionDetailsDto actionDetailsDto, Action action, bool isClosed)
 {
     Assert.AreEqual(action.Id, actionDetailsDto.Id);
     Assert.AreEqual(action.Title, actionDetailsDto.Title);
     Assert.AreEqual(action.Description, actionDetailsDto.Description);
     Assert.AreEqual(action.IsClosed, actionDetailsDto.IsClosed);
     Assert.AreEqual(action.DueTimeUtc, actionDetailsDto.DueTimeUtc);
     Assert.AreEqual(action.ClosedAtUtc, actionDetailsDto.ClosedAtUtc);
     Assert.AreEqual(isClosed, actionDetailsDto.IsClosed);
     Assert.AreEqual(action.Attachments.Count, actionDetailsDto.AttachmentCount);
 }
Esempio n. 10
0
        public void IsOverDue_ShouldBeFalseWhenDueDateInFuture()
        {
            // Arrange
            _dut = new Action(TestPlant, "TitleA", "DescA", _utcNow.AddHours(1));

            // Act
            var overDue = _dut.IsOverDue();

            // Assert
            Assert.IsFalse(overDue);
        }
Esempio n. 11
0
        public void IsOverDue_ShouldBeTrueWhenDueDateInPast()
        {
            // Arrange
            _dut = new Action(TestPlant, "TitleA", "DescA", _utcNow);
            _timeProvider.Elapse(new TimeSpan(1, 0, 0));

            // Act
            var overDue = _dut.IsOverDue();

            // Assert
            Assert.IsTrue(overDue);
        }
Esempio n. 12
0
        public void Constructor_ShouldSetProperties_WithoutDue()
        {
            _dut = new Action(TestPlant, "TitleA", "DescA", null);

            Assert.AreEqual(TestPlant, _dut.Plant);
            Assert.IsFalse(_dut.DueTimeUtc.HasValue);
            Assert.IsFalse(_dut.ClosedById.HasValue);
            Assert.IsNull(_dut.ClosedAtUtc);
            Assert.AreEqual("TitleA", _dut.Title);
            Assert.AreEqual("DescA", _dut.Description);
            Assert.IsFalse(_dut.IsClosed);
        }
Esempio n. 13
0
        public void IsOverDue_ShouldBeFalseWhenDueDateInPast_ButClosed()
        {
            // Arrange
            _dut = new Action(TestPlant, "TitleA", "DescA", _utcNow);
            _timeProvider.Elapse(new TimeSpan(1, 0, 0));
            _dut.Close(_utcNow, _personMock.Object);

            // Act
            var overDue = _dut.IsOverDue();

            // Assert
            Assert.IsFalse(overDue);
        }
Esempio n. 14
0
 private void AssertAction(ActionDto actionDto, Action action, PCSPlant plant, Project project)
 {
     AssertEqualAndNotNull(plant.Id, actionDto.PlantId);
     AssertEqualAndNotNull(plant.Title, actionDto.PlantTitle);
     AssertEqualAndNotNull(project.Name, actionDto.ProjectName);
     AssertEqualAndNotNull(project.Description, actionDto.ProjectDescription);
     Assert.AreEqual(project.IsClosed, actionDto.ProjectIsClosed);
     AssertEqualAndNotNull(action.Id, actionDto.Id);
     Assert.AreEqual(action.IsOverDue(), actionDto.IsOverDue);
     AssertEqualAndNotNull(action.Title, actionDto.Title);
     AssertEqualAndNotNull(action.Description, actionDto.Description);
     Assert.AreEqual(action.IsClosed, actionDto.IsClosed);
     Assert.AreEqual(action.DueTimeUtc, actionDto.DueTimeUtc);
     AssertEqualAndNotNull(action.Attachments.Count, actionDto.AttachmentCount);
 }
Esempio n. 15
0
        protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions)
        {
            using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                _testDataSet = AddTestDataSet(context);

                var tag        = _testDataSet.Project1.Tags.First();
                var attachment = new ActionAttachment(TestPlant, Guid.NewGuid(), "FileA");

                _openAction = new Action(TestPlant, "Open", "Desc1", _utcNow);
                tag.AddAction(_openAction);
                _closedAction = new Action(TestPlant, "Closed", "Desc2", _utcNow);
                _closedAction.Close(_utcNow, _testDataSet.CurrentUser);
                tag.AddAction(_closedAction);

                var tag2 = _testDataSet.Project1.Tags.Last();

                var personMock = new Mock <Person>();
                personMock.SetupGet(p => p.Id).Returns(7);

                _openActionWithEarliestDueTime = new Action(TestPlant, "OpenWithEarliestDueTime", "D2", _dueTimeUtc);
                _openActionWithDueTime         = new Action(TestPlant, "OpenWithDueTime", "D1", _dueTimeUtc);
                _openActionWithoutDueTime      = new Action(TestPlant, "OpenWithoutDueTime", "D3", _dueTimeUtc);
                _openActionWithoutDueTime.SetDueTime(null);
                _openAction.AddAttachment(attachment);
                _closedActionWithEarliestDueTime = new Action(TestPlant, "ClosedWithEarliestDueTime", "D5", _dueTimeUtc);
                _closedActionWithEarliestDueTime.Close(_utcNow, personMock.Object);
                _closedActionWithDueTime = new Action(TestPlant, "ClosedWithDueTime", "D4", _dueTimeUtc);
                _closedActionWithDueTime.Close(_utcNow, personMock.Object);
                _closedActionWithoutDueTime = new Action(TestPlant, "ClosedWithoutDueTime", "D6", _dueTimeUtc);
                _closedActionWithoutDueTime.SetDueTime(null);
                _closedActionWithoutDueTime.Close(_utcNow, personMock.Object);

                tag2.AddAction(_openActionWithoutDueTime);
                tag2.AddAction(_closedActionWithoutDueTime);
                tag2.AddAction(_openActionWithDueTime);
                tag2.AddAction(_closedActionWithDueTime);
                tag2.AddAction(_openActionWithEarliestDueTime);
                tag2.AddAction(_closedActionWithEarliestDueTime);

                context.SaveChangesAsync().Wait();

                _tagId          = tag.Id;
                _tag2Id         = tag2.Id;
                _openActionId   = _openAction.Id;
                _closedActionId = _closedAction.Id;
            }
        }
Esempio n. 16
0
        public void Setup()
        {
            _command = new DeleteActionAttachmentCommand(1, 2, 3, _rowVersion);

            _projectRepositoryMock = new Mock <IProjectRepository>();
            _blobStorageMock       = new Mock <IBlobStorage>();

            var attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >();
            var options = new AttachmentOptions
            {
                MaxSizeMb         = 2,
                BlobContainer     = BlobContainer,
                ValidFileSuffixes = new[] { ".gif", ".jpg" }
            };

            attachmentOptionsMock
            .Setup(x => x.CurrentValue)
            .Returns(options);

            var tagMock = new Mock <Tag>();

            tagMock.SetupGet(t => t.Plant).Returns(TestPlant);

            _action = new Action(TestPlant, "T", "D", null);
            _action.SetProtectedIdForTesting(_command.ActionId);
            tagMock.Object.AddAction(_action);

            var attachment = new ActionAttachment(TestPlant, Guid.Empty, "Fil.txt");

            attachment.SetProtectedIdForTesting(_command.AttachmentId);
            _action.AddAttachment(attachment);

            _projectRepositoryMock
            .Setup(r => r.GetTagByTagIdAsync(_command.TagId))
            .Returns(Task.FromResult(tagMock.Object));

            _dut = new DeleteActionAttachmentCommandHandler(
                _projectRepositoryMock.Object,
                UnitOfWorkMock.Object,
                _blobStorageMock.Object,
                attachmentOptionsMock.Object);
        }
        protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions)
        {
            using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                _testDataSet = AddTestDataSet(context);

                var tag = _testDataSet.Project1.Tags.First();

                var action = new Action(TestPlant, "Open", "Desc1", _utcNow);
                tag.AddAction(action);

                _attachment = new ActionAttachment(TestPlant, new Guid("{C3412890-1EF8-4E34-B96C-5488200A5AF5}"), "FileA");
                action.AddAttachment(_attachment);

                context.SaveChangesAsync().Wait();

                _tagId    = tag.Id;
                _actionId = action.Id;
            }
        }
        public void Setup()
        {
            _commandWithoutOverwrite = new UploadActionAttachmentCommand(_tagId, _actionId, _fileName, false, new MemoryStream());

            _projectRepositoryMock = new Mock <IProjectRepository>();
            _blobStorageMock       = new Mock <IBlobStorage>();

            var attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >();
            var options = new AttachmentOptions
            {
                MaxSizeMb         = 2,
                BlobContainer     = _blobContainer,
                ValidFileSuffixes = new[] { ".gif", ".jpg" }
            };

            attachmentOptionsMock
            .Setup(x => x.CurrentValue)
            .Returns(options);

            var tagMock = new Mock <Tag>();

            tagMock.SetupGet(t => t.Plant).Returns(TestPlant);
            _action = new Action(TestPlant, "T", "D", null);
            _action.SetProtectedIdForTesting(_commandWithoutOverwrite.ActionId);
            tagMock.Object.AddAction(_action);

            _projectRepositoryMock
            .Setup(r => r.GetTagByTagIdAsync(_tagId))
            .Returns(Task.FromResult(tagMock.Object));


            _dut = new UploadActionAttachmentCommandHandler(
                _projectRepositoryMock.Object,
                UnitOfWorkMock.Object,
                PlantProviderMock.Object,
                _blobStorageMock.Object,
                attachmentOptionsMock.Object);
        }
Esempio n. 19
0
        protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions)
        {
            _blobStorageMock       = new Mock <IBlobStorage>();
            _uri                   = new Uri("http://whatever/file.txt");
            _attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >();
            var options = new AttachmentOptions
            {
                BlobContainer = BlobContainer
            };

            _attachmentOptionsMock
            .Setup(x => x.CurrentValue)
            .Returns(options);

            using var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider);

            _testDataSet = AddTestDataSet(context);

            var tag    = _testDataSet.Project1.Tags.First();
            var action = new Action(TestPlant, "Open", "Desc1", _utcNow);

            tag.AddAction(action);

            _attachment = new ActionAttachment(TestPlant, Guid.NewGuid(), "FileA");
            action.AddAttachment(_attachment);

            context.SaveChangesAsync().Wait();

            _tagId        = tag.Id;
            _actionId     = action.Id;
            _attachmentId = _attachment.Id;

            var fullBlobPath = _attachment.GetFullBlobPath(BlobContainer);

            _blobStorageMock
            .Setup(b => b.GetDownloadSasUri(fullBlobPath, It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>()))
            .Returns(_uri);
        }
Esempio n. 20
0
        protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions)
        {
            using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                _testDataSet = AddTestDataSet(context);

                var tag        = _testDataSet.Project1.Tags.First();
                var attachment = new ActionAttachment(TestPlant, Guid.NewGuid(), "FileA");

                _openAction = new Action(TestPlant, "Open", "Desc1", _dueUtc);
                _openAction.AddAttachment(attachment);
                tag.AddAction(_openAction);

                _closedAction = new Action(TestPlant, "Closed", "Desc2", _dueUtc);
                _closedAction.Close(_utcNow, _testDataSet.CurrentUser);
                tag.AddAction(_closedAction);
                context.SaveChangesAsync().Wait();

                _tagId          = tag.Id;
                _openActionId   = _openAction.Id;
                _closedActionId = _closedAction.Id;
            }
        }
        public void Setup()
        {
            _projectRepositoryMock = new Mock <IProjectRepository>();
            _personRepositoryMock  = new Mock <IPersonRepository>();

            var tagId   = 2;
            var tagMock = new Mock <Tag>();

            tagMock.SetupGet(t => t.Plant).Returns(TestPlant);
            tagMock.SetupGet(t => t.Id).Returns(tagId);
            _action = new Action(TestPlant, "T", "D", null);
            var actionId = 12;

            _action.SetProtectedIdForTesting(actionId);
            tagMock.Object.AddAction(_action);

            _personMock = new Mock <Person>();
            _personMock.SetupGet(p => p.Id).Returns(_personId);

            _projectRepositoryMock
            .Setup(r => r.GetTagByTagIdAsync(tagId))
            .Returns(Task.FromResult(tagMock.Object));

            _personRepositoryMock
            .Setup(p => p.GetByOidAsync(It.Is <Guid>(x => x == CurrentUserOid)))
            .Returns(Task.FromResult(_personMock.Object));

            _command = new CloseActionCommand(tagId, actionId, _rowVersion);

            _dut = new CloseActionCommandHandler(
                _projectRepositoryMock.Object,
                UnitOfWorkMock.Object,
                _personRepositoryMock.Object,
                CurrentUserProviderMock.Object
                );
        }
        protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions)
        {
            using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var project = AddProject(context, "P", "Project description");
                var journey = AddJourneyWithStep(context, "J", "S1", AddMode(context, "M1", false), AddResponsible(context, "R1"));
                var rd      = AddRequirementTypeWith1DefWithoutField(context, "Rot", "D", _reqIconOther).RequirementDefinitions.First();

                var tag = AddTag(context, project, TagType.Standard, "TagNo", "Tag description", journey.Steps.First(),
                                 new List <TagRequirement> {
                    new TagRequirement(TestPlant, 2, rd)
                });

                var action = new Action(TestPlant, "A", "D", null);
                tag.AddAction(action);

                var attachment = new ActionAttachment(TestPlant, Guid.Empty, _filename);
                action.AddAttachment(attachment);

                context.SaveChangesAsync().Wait();

                _actionId = action.Id;
            }
        }