예제 #1
0
        public async Task TestDeleteFileOperation(bool throws, OperationState state)
        {
            var directoryServiceMock = new Mock <IDirectoryService>();
            var filesServiceMock     = new Mock <IFileService>();
            var removeSetup          = filesServiceMock
                                       .Setup(m => m.Remove(SourceName));

            if (throws)
            {
                removeSetup.Throws(new AccessViolationException()).Verifiable();
            }
            else
            {
                removeSetup.Verifiable();
            }
            var pathServiceMock = new Mock <IPathService>();

            var operationsFactory = new OperationsFactory(
                _taskPool,
                directoryServiceMock.Object,
                filesServiceMock.Object,
                pathServiceMock.Object,
                _fileNameGenerationService);
            var deleteOperation = operationsFactory.CreateDeleteOperation(
                new UnaryFileSystemOperationSettings(new string[] {}, new[] { SourceName }, SourceName));

            Assert.Equal(OperationState.NotStarted, deleteOperation.State);
            var callbackCalled = false;

            deleteOperation.StateChanged += (sender, args) => callbackCalled = true;

            await deleteOperation.RunAsync();

            Assert.Equal(state, deleteOperation.State);

            Assert.True(callbackCalled);
            filesServiceMock.Verify(m => m.Remove(SourceName), Times.Once());
        }
예제 #2
0
        public async Task TestCopyOperation()
        {
            var directoryServiceMock = new Mock <IDirectoryService>();
            var filesServiceMock     = new Mock <IFileService>();

            filesServiceMock
            .Setup(m => m.CopyAsync(SourceName, DestinationName, false))
            .Verifiable();
            var operationsFactory = new OperationsFactory(
                _taskPool,
                directoryServiceMock.Object,
                filesServiceMock.Object,
                _pathService,
                _fileNameGenerationService);
            var settings = new BinaryFileSystemOperationSettings(
                new string[] { },
                new[] { SourceName },
                new string[] { },
                new[] { SourceName },
                new Dictionary <string, string> {
                [SourceName] = DestinationName
            }
                );
            var copyOperation = operationsFactory.CreateCopyOperation(settings);

            Assert.Equal(OperationState.NotStarted, copyOperation.State);

            var callbackCalled = false;

            copyOperation.StateChanged += (sender, args) => callbackCalled = true;

            await copyOperation.RunAsync();

            Assert.Equal(OperationState.Finished, copyOperation.State);

            Assert.True(callbackCalled);
            filesServiceMock.Verify(m => m.CopyAsync(SourceName, DestinationName, false), Times.Once());
        }
예제 #3
0
        public ActionResult ShowAllBlogPost(BlogPostAllVM model)
        {
            var categoryId  = model.SelectedCategoryId;
            var hashtagId   = model.SelectedHashtagId;
            var categoryOps = OperationsFactory.CreateCategoryOps();
            var hashtagOps  = OperationsFactory.CreateHashtagOps();
            var ops         = OperationsFactory.CreateBlogPostOps();

            if (categoryId != 0)
            {
                model.BlogPosts = ops.ListAllBlogsInCategoryByCategoryId(categoryId).FindAll(x => x.Status.StatusID == 2)
                                  .FindAll(x => x.DateOfPost <= DateTime.Today)
                                  .OrderByDescending(x => x.DateOfPost)
                                  .ToList();
                var firstOrDefault = categoryOps.ListAllCategories().FirstOrDefault(x => x.CategoryID == categoryId);
                if (firstOrDefault != null)
                {
                    model.SelectedCategoryName =
                        firstOrDefault.CategoryType;
                }
            }
            else
            {
                model.BlogPosts = ops.ListAllBlogsByHashTag(hashtagId).FindAll(x => x.Status.StatusID == 2)
                                  .FindAll(x => x.DateOfPost <= DateTime.Today)
                                  .OrderByDescending(x => x.DateOfPost)
                                  .ToList();
                var firstOrDefault = hashtagOps.ListAllHashtags().FirstOrDefault(x => x.HashtagID == hashtagId);
                if (firstOrDefault != null)
                {
                    model.SelectedHashtagName =
                        firstOrDefault.HashtagType;
                }
            }

            return(View(model));
        }
        public void EditPtoRequestTest()
        {
            //tests against DB; altered test app config setting
            var         ops        = OperationsFactory.CreatePaidTimeOffOperations();
            PaidTimeOff ptoRequest = new PaidTimeOff()
            {
                PtoRequestID   = 1,
                PtoStatus      = "Approved",
                EmpID          = 5,
                Date           = new DateTime(2015, 07, 15),
                HoursRequested = 4,
                ManagerID      = 2,
                ReasonRejected = "N/A"
            };
            PaidTimeOffRepository repo = new PaidTimeOffRepository();

            repo.EditPtoRequest(ptoRequest);
            var response = new Response <List <PaidTimeOff> >();

            response = ops.ViewAllPtoRequests();
            PaidTimeOff updatedPto = response.Data.FirstOrDefault(p => p.PtoRequestID == 1);

            Assert.AreEqual("Approved", updatedPto.PtoStatus);
        }
예제 #5
0
 /// <summary>
 /// Enables following execution expressions if the
 /// current object is Null
 /// </summary>
 /// <param name="obj">Nullable object</param>
 /// <returns>Set of valid operations</returns>
 public static Operations.Operations IfNull(this object obj)
 => OperationsFactory.GetOperations(obj == null);
        public void TestFabrykiPrawidlowyArgument(string argument, Type expected)
        {
            var actual = OperationsFactory.ChooseOperation(argument);

            Assert.AreEqual(expected, actual.GetType());
        }
예제 #7
0
 /// <summary>
 /// Enables following execution expressions if the
 /// current evaluated expression is False
 /// </summary>
 /// <param name="expression">Boolean expression</param>
 /// <returns>Set of valid operations</returns>
 public static Operations.Operations IfFalse(this bool expression)
 => OperationsFactory.GetOperations(!expression);
예제 #8
0
 /// <summary>
 /// Enables following execution expressions if the
 /// current evaluated expression is True
 /// </summary>
 /// <param name="expression">Boolean expression</param>
 /// <returns>Set of valid operations</returns>
 public static Operations.Operations IfTrue(this bool expression)
 => OperationsFactory.GetOperations(expression);
예제 #9
0
 public void OperationForLog()
 {
     OperationsFactory.CreateTrigonometriaOperation("Sec").GetType();
 }
예제 #10
0
        public void FactoryTest(Type type, string name)
        {
            Type resultType = OperationsFactory.CreateTrigonometriaOperation(name).GetType();

            Assert.AreEqual(type, resultType);
        }
예제 #11
0
 public void OperationForLog()
 {
     OperationsFactory.CreateOperation("Log").GetType();
 }
예제 #12
0
        public async Task TestBlockedCopyOperation(bool applyToAll, int expectedCallbackCallsCount,
                                                   OperationContinuationMode mode, int expectedWriteCallsCountFirstFile, int expectedWriteCallsCountSecondFile)
        {
            var now           = DateTime.UtcNow;
            var hourBeforeNow = now.AddHours(-1);

            var directoryServiceMock = new Mock <IDirectoryService>();
            var filesServiceMock     = new Mock <IFileService>();

            filesServiceMock
            .Setup(m => m.GetFile(SourceName))
            .Returns(new FileModel {
                LastModifiedDateTime = now
            });
            filesServiceMock
            .Setup(m => m.GetFile(DestinationName))
            .Returns(new FileModel {
                LastModifiedDateTime = hourBeforeNow
            });
            filesServiceMock
            .Setup(m => m.GetFile(SecondSourceName))
            .Returns(new FileModel {
                LastModifiedDateTime = hourBeforeNow
            });
            filesServiceMock
            .Setup(m => m.GetFile(SecondDestinationName))
            .Returns(new FileModel {
                LastModifiedDateTime = now
            });
            filesServiceMock
            .Setup(m => m.CopyAsync(SourceName, DestinationName, false))
            .Verifiable();
            filesServiceMock
            .Setup(m => m.CopyAsync(SourceName, DestinationName, true))
            .Returns(Task.CompletedTask)
            .Verifiable();
            filesServiceMock
            .Setup(m => m.CopyAsync(SecondSourceName, SecondDestinationName, false))
            .Verifiable();
            filesServiceMock
            .Setup(m => m.CopyAsync(SecondSourceName, SecondDestinationName, true))
            .Returns(Task.CompletedTask)
            .Verifiable();
            filesServiceMock
            .Setup(m => m.CheckIfExists(It.IsAny <string>()))
            .Returns(true);
            var operationsFactory = new OperationsFactory(
                _taskPool,
                directoryServiceMock.Object,
                filesServiceMock.Object,
                _pathService,
                _fileNameGenerationService);
            var settings = new BinaryFileSystemOperationSettings(
                new string[] { },
                new[] { SourceName, SecondSourceName },
                new string[] { },
                new[] { DestinationName, SecondDestinationName },
                new Dictionary <string, string>
            {
                [SourceName]       = DestinationName,
                [SecondSourceName] = SecondDestinationName
            },
                new string[] { }
                );
            var copyOperation = operationsFactory.CreateCopyOperation(settings);

            var callbackCallsCount = 0;

            copyOperation.StateChanged += async(sender, args) =>
            {
                if (args.OperationState != OperationState.Blocked)
                {
                    return;
                }

                var operation = (IOperation)sender;
                if (operation is null)
                {
                    return;
                }

                callbackCallsCount++;

                var(sourceFilePath, _) = operation.CurrentBlockedFile;
                var options = OperationContinuationOptions.CreateContinuationOptions(sourceFilePath, applyToAll, mode);

                await copyOperation.ContinueAsync(options);
            };

            await copyOperation.RunAsync();

            Assert.Equal(expectedCallbackCallsCount, callbackCallsCount);

            Assert.Equal(OperationState.Finished, copyOperation.State);
            filesServiceMock.Verify(m => m.CopyAsync(SourceName, DestinationName, true), Times.Exactly(expectedWriteCallsCountFirstFile));
            filesServiceMock.Verify(m => m.CopyAsync(SecondSourceName, SecondDestinationName, true), Times.Exactly(expectedWriteCallsCountSecondFile));
            filesServiceMock.Verify(m => m.CopyAsync(SourceName, DestinationName, false), Times.Never);
            filesServiceMock.Verify(m => m.CopyAsync(SecondSourceName, SecondDestinationName, false), Times.Never);
        }
예제 #13
0
        public PartialViewResult StaticPagePartial()
        {
            var ops = OperationsFactory.CreateStaticPageOps();

            return(PartialView("_StaticPagePartial", ops.GetAllStaticPages()));
        }