Example #1
0
        public void WhenExecuteCommandWithTemplateNameRepeated_CommandManager_ShouldThrowException()
        {
            string templatePath      = "myPath";
            string templateName      = "myTemplate";
            var    storedDataService = new StoredDataServiceMock()
            {
                ExistsTemplateReturn = true
            };
            var fileService       = new FileServiceMock();
            var commandDefinition = new AddTemplateCommand(storedDataService, fileService);

            var instance = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathParameter.GetInvokeName(),
                templatePath,
                commandDefinition.CommandNameParameter.GetInvokeName(),
                templateName);

            Assert.Throws <TemplateNameRepeatedException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
Example #2
0
        public void WhenExecuteCommandWithoutOldValueParameter_CommandManager_ShouldThrowException()
        {
            var path     = "mypath";
            var newValue = "myOldValue";

            var storedDataService = new StoredDataServiceMock();

            var fileServiceMock   = new FileServiceMock();
            var commandDefinition = new ReplaceFileContentCommand(fileServiceMock);
            var instance          = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathParameter.GetInvokeName(),
                path,
                commandDefinition.CommandNewValueParameter.GetInvokeName(),
                newValue);

            Assert.Throws <InvalidParamsException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
 public void Initialize()
 {
     InitializeStubIntegrationTest("Resources/integration.yml");
     FileServiceMock
     .Setup(m => m.GetTempPath())
     .Returns(OperatingSystem.IsWindows() ? @"C:\Windows\Temp" : "/tmp");
 }
Example #4
0
        public async Task Put_Success()
        {
            // Arrange
            var dbContext        = _fixture.Context;
            var mapper           = MapperMock.Get();
            var fileService      = FileServiceMock.FilesService();
            var productToPut     = NewDatas.NewProductPutRequest();
            var productBeforePut = NewDatas.NewProduct(); productBeforePut.productId = 10; //set productId in order to update
            var productAfterPut  = NewDatas.ProductAfterPut();
            var category         = NewDatas.NewCategory();

            await dbContext.Categories.AddAsync(category);

            await dbContext.Products.AddAsync(productBeforePut);

            await dbContext.SaveChangesAsync(); productToPut.categoryId = category.categoryId;
            var productsService    = new ProductService(dbContext, fileService, mapper);
            var productsController = new ProductsController(productsService, fileService);
            // Act
            var result = await productsController.PutProduct(10, productToPut);

            // Assert
            Assert.IsType <OkObjectResult>(result.Result);

            Assert.Equal(productBeforePut.productName, productAfterPut.productName);
            Assert.Equal(productBeforePut.productPrice, productAfterPut.productPrice);
            Assert.Equal(productBeforePut.productDescription, productAfterPut.productDescription);
            Assert.Equal(productBeforePut.Images.Count, productAfterPut.Images.Count);
            Assert.Equal(productBeforePut.Category, category);
        }
Example #5
0
        public void WhenExecuteCommandWithoutNonExistingSourcePath_CommandManager_ShouldThrowException()
        {
            var mySourcePath      = "mypath";
            var myDestinationPath = "mypath";
            var storedDataService = new StoredDataServiceMock();

            var fileServiceMock = new FileServiceMock()
            {
                ExistsPathReturn = false
            };
            var commandDefinition = new MovePathCommand(fileServiceMock);
            var instance          = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandSourcePathParameter.GetInvokeName(),
                mySourcePath,
                commandDefinition.CommandDestinationFolderParameter.GetInvokeName(),
                myDestinationPath);

            Assert.Throws <PathNotFoundException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
Example #6
0
        public void WhenExecuteCommandWithDirectoryPath_CommandManager_ShouldExecuteMoveDirectoryContent()
        {
            var mySourcePath      = "mypath";
            var myDestinationPath = "mypath";
            var storedDataService = new StoredDataServiceMock();

            var fileServiceMock = new FileServiceMock()
            {
                ExistsPathReturn = true, IsDirectoryReturn = true
            };
            var commandDefinition = new MovePathCommand(fileServiceMock);
            var instance          = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandSourcePathParameter.GetInvokeName(),
                mySourcePath,
                commandDefinition.CommandDestinationFolderParameter.GetInvokeName(),
                myDestinationPath);

            instance.ExecuteInputRequest(inputRequest);

            var expectedSourcePath       = mySourcePath;
            var expectedDestionationPath = myDestinationPath;
            var actualSourcePath         = fileServiceMock.MovedSourceFolder;
            var actualDestinationPath    = fileServiceMock.MovedDestionationFolder;

            Assert.Equal(expectedSourcePath, actualSourcePath);
            Assert.Equal(expectedDestionationPath, actualDestinationPath);
        }
Example #7
0
        public void WhenExecuteCommandWithPipelineNonValidPipelineName_CommandManager_ShouldThrowException()
        {
            string pipelinePath      = "myPath";
            string pipelineName      = "myPipe NONVALID line";
            var    storedDataService = new StoredDataServiceMock()
            {
                ExistsPipelineReturn = false
            };
            var fileService = new FileServiceMock()
            {
                ExistsFileReturn = true
            };
            var commandDefinition = new AddPipelineCommand(storedDataService, fileService);

            var instance = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathParameter.GetInvokeName(),
                pipelinePath,
                commandDefinition.CommandNameParameter.GetInvokeName(),
                pipelineName);

            Assert.Throws <InvalidStringFormatException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
Example #8
0
        public void WhenExecuteCommandWithValidFolder_CommandManager_ShouldZipDirectory()
        {
            var path = "myPath";
            var storedDataService = new StoredDataServiceMock(false);

            var fileServiceMock = new FileServiceMock()
            {
                IsFileReturn = true
            };
            var commandDefinition = new UnzipCommand(fileServiceMock);
            var instance          = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathParameter.GetInvokeName(),
                path);

            instance.ExecuteInputRequest(inputRequest);

            var expected = path;
            var actual   = fileServiceMock.UnzippedPath;

            Assert.Equal(expected, actual);
        }
Example #9
0
        public void WhenExecuteCommandWithValidPaths_CommandManager_ShouldRename()
        {
            var newPath           = "myNewPath";
            var oldPath           = "myOldPath";
            var storedDataService = new StoredDataServiceMock(false);

            var fileServiceMock   = new FileServiceMock();
            var commandDefinition = new RenameFolderCommand(fileServiceMock);
            var instance          = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathOldFolderParameter.GetInvokeName(),
                oldPath,
                commandDefinition.CommandPathNewFolderParameter.GetInvokeName(),
                newPath);

            instance.ExecuteInputRequest(inputRequest);

            var expectedOldPath  = oldPath;
            var expectedONewPath = newPath;
            var actualOldPath    = fileServiceMock.RenamedOldFolder;
            var actualNewPath    = fileServiceMock.RenamedNewFolder;

            Assert.Equal(expectedOldPath, actualOldPath);
            Assert.Equal(expectedONewPath, actualNewPath);
        }
Example #10
0
        public void WhenExecuteCommandWithValidTemplateConfig_CommandManager_ShouldExecuteReplaces()
        {
            var myAbsolutePath = @"c:\absolute\my\Path";
            var myPath         = @"my\Path";
            var myTemplateName = "My template name";
            var myNewPathName  = "MySecondApp";
            var myOldValue     = "myOldValue";
            var myNewVale      = "myNewValue";
            var fileService    = new FileServiceMock()
            {
                DDTemplateConfigReturn = new DDTemplateConfig()
                {
                    TemplateName       = myTemplateName,
                    IgnorePathPatterns = new List <string>(),
                    ReplacePairs       = new List <ReplacePair>()
                    {
                        new ReplacePair()
                        {
                            ApplyForDirectories  = true,
                            ApplyForFileContents = true,
                            ApplyForFileNames    = true,
                            ApplyForFilePattern  = "*.*",
                            OldValue             = myOldValue,
                            ReplaceDescription   = "My replace description"
                        }
                    }
                },
                ExistsTemplateConfigFileReturn = true,
                ExistsDirectoryReturn          = true,
                AbsoluteCurrentPathReturn      = myAbsolutePath
            };

            var consoleInputs = new List <string>()
            {
                myNewPathName,
                myNewVale
            };

            var commandDefinition = new TemplateCommand(fileService, _storedDataService);

            var instance = new CommandManager(_loggerServiceMock, _storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathParameter.GetInvokeName(),
                myPath);

            instance.ExecuteInputRequest(inputRequest, consoleInputs);

            //Assert.Equal(fileService.CreatedDirectory, myAbsolutePath);
            Assert.Equal(fileService.ClonedDirectorySource, myPath);
            Assert.Equal(fileService.ClonedDirectoryDestination, myAbsolutePath);
            Assert.Equal(fileService.ReplacedStringInPathsNewValue, myNewVale);
            Assert.Equal(fileService.ReplacedStringInPathsOldValue, myOldValue);
            Assert.Equal(fileService.ReplacedFilesContentsPath, myAbsolutePath);
            Assert.Equal(fileService.ReplacedFilesNamesPath, myAbsolutePath);
            Assert.Equal(fileService.ReplacedSubDirectoriesPath, myAbsolutePath);
        }
        public async Task GetSingle_Success()
        {
            var dbContext   = _fixture.Context;
            var mapper      = MapperMock.Get();
            var fileService = FileServiceMock.FilesService();
            var user        = NewDatas.NewUser();
            await dbContext.Users.AddAsync(user);

            await dbContext.SaveChangesAsync();

            var product1 = NewDatas.NewProduct();
            var product2 = NewDatas.NewProduct();
            var product3 = NewDatas.NewProduct();
            await dbContext.Products.AddRangeAsync(product1, product2, product3);

            await dbContext.SaveChangesAsync();

            var order = NewDatas.NewOrder();

            dbContext.Orders.Add(order);
            await dbContext.SaveChangesAsync();

            var orderDetail1 = NewDatas.NewOrderDetail();

            orderDetail1.productId = product1.productId;
            orderDetail1.orderId   = order.orderId;
            var orderDetail2 = NewDatas.NewOrderDetail();

            orderDetail2.productId = product2.productId;
            orderDetail2.orderId   = order.orderId;
            var orderDetail3 = NewDatas.NewOrderDetail();

            orderDetail3.productId = product3.productId;
            orderDetail3.orderId   = order.orderId;
            await dbContext.OrderDetails.AddRangeAsync(orderDetail1, orderDetail2, orderDetail3);

            await dbContext.SaveChangesAsync();

            order.orderDetails = new List <OrderDetail> {
                orderDetail1, orderDetail2, orderDetail3
            };
            order.user = user;
            await dbContext.SaveChangesAsync();

            var ordersService    = new OrderService(dbContext, mapper);
            var ordersController = new OrdersController(ordersService, mapper, fileService);
            // Act
            var result = await ordersController.GetOrder(order.orderId);

            // Assert
            var ordersResult = Assert.IsType <OkObjectResult>(result.Result);

            Assert.NotNull(ordersResult.Value as Order);
        }
        public async void GetAll_Success()
        {
            // Arrange
            var dbContext = _fixture.Context;
            var mapper    = MapperMock.Get();

            var user = NewDatas.NewUser();
            await dbContext.Users.AddAsync(user);

            await dbContext.SaveChangesAsync();

            var product1 = NewDatas.NewProduct();
            var product2 = NewDatas.NewProduct();
            var product3 = NewDatas.NewProduct();
            await dbContext.Products.AddRangeAsync(product1, product2, product3);

            await dbContext.SaveChangesAsync();

            #region create intial order data
            var fileService = FileServiceMock.FilesService();
            var order       = NewDatas.NewOrder();
            dbContext.Orders.Add(order);
            await dbContext.SaveChangesAsync();

            var orderDetail1 = NewDatas.NewOrderDetail();
            orderDetail1.productId = product1.productId;
            orderDetail1.orderId   = order.orderId;
            var orderDetail2 = NewDatas.NewOrderDetail();
            orderDetail2.productId = product2.productId;
            orderDetail2.orderId   = order.orderId;
            var orderDetail3 = NewDatas.NewOrderDetail();
            orderDetail3.productId = product3.productId;
            orderDetail3.orderId   = order.orderId;
            await dbContext.OrderDetails.AddRangeAsync(orderDetail1, orderDetail2, orderDetail3);

            await dbContext.SaveChangesAsync();

            order.orderDetails = new List <OrderDetail> {
                orderDetail1, orderDetail2, orderDetail3
            };
            order.user = user;
            await dbContext.SaveChangesAsync();

            #endregion
            var ordersService    = new OrderService(dbContext, mapper);
            var ordersController = new OrdersController(ordersService, mapper, fileService);
            // Act
            var result = await ordersController.GetOrders();

            // Assert
            var ordersResult = Assert.IsType <OkObjectResult>(result.Result);
            Assert.NotEmpty(ordersResult.Value as IEnumerable <OrderResponse>);
        }
Example #13
0
        public void WhenExecuteCommand_AddWPFControlCommand_ShouldGenerateFiles()
        {
            var controllerReplaced1 = "ControllerPathContent";
            var viewModelReplaced2  = "ViewModelPathContent";
            var ViewReplaced3       = "ViewPathContent";
            var className           = "MyClass";

            var storedDataService = new StoredDataServiceMock(false);

            var instance = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            var fileService = new FileServiceMock();

            var replacementParameter = new Dictionary <string, string>();

            replacementParameter["ClassName"] = className;


            var templateService = new TemplateReplacementServiceMock()
            {
                ReturnParameters = replacementParameter,
                ReturnedContents = new List <string>()
                {
                    controllerReplaced1,
                    viewModelReplaced2,
                    ViewReplaced3
                }
            };
            var commandDefinition = new AddWPFUserControlCommand(fileService, templateService);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName());

            instance.ExecuteInputRequest(inputRequest);

            var expectedPath1 = controllerReplaced1;
            var actualPath1   = fileService.FilesWritten[0];

            var expectedPath2 = viewModelReplaced2;
            var actualPath2   = fileService.FilesWritten[1];

            var expectedPath3 = ViewReplaced3;
            var actualPath3   = fileService.FilesWritten[2];


            Assert.Equal(expectedPath1, actualPath1);
            Assert.Equal(expectedPath2, actualPath2);
            Assert.Equal(expectedPath3, actualPath3);
        }
        public async Task Post_Success()
        {
            // Arrange
            var dbContext     = _fixture.Context;
            var mapper        = MapperMock.Get();
            var fileService   = FileServiceMock.FilesService();
            var productToPost = NewDatas.NewProductPostRequest();

            var productsService    = new ProductService(dbContext, fileService, mapper);
            var productsController = new ProductsController(productsService, fileService);
            // Act
            var result = await productsController.PostProduct(productToPost);

            // Assert
            Assert.IsType <CreatedAtActionResult>(result.Result);
        }
Example #15
0
        public void WhenExecuteCommandWithoutPathParameter_CommandManager_ShouldThrowException()
        {
            var fileService       = new FileServiceMock();
            var commandDefinition = new TemplateCommand(fileService, _storedDataService);

            var instance = new CommandManager(_loggerServiceMock, _storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName());

            Assert.Throws <InvalidParamsException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
        public async Task Post_Success()
        {
            // Arrange
            var dbContext = _fixture.Context;
            var mapper    = MapperMock.Get();

            var fileService = FileServiceMock.FilesService();

            var user = NewDatas.NewUser();
            await dbContext.Users.AddAsync(user);

            await dbContext.SaveChangesAsync();

            var product1 = NewDatas.NewProduct();
            await dbContext.Products.AddAsync(product1);

            await dbContext.SaveChangesAsync();

            var orderCreateRequest = NewDatas.NewOrderDetailRequest();

            orderCreateRequest.productId = product1.productId;

            var ordersService    = new OrderService(dbContext, mapper);
            var ordersController = new OrdersController(ordersService, mapper, fileService);

            #region set controller user
            ordersController.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
                    {
                        new Claim(ClaimTypes.Name, user.UserName),
                        new Claim(ClaimTypes.NameIdentifier, user.Id.ToString(CultureInfo.InvariantCulture))
                    }, "Bearer")
                                               )
                }
            };
            #endregion
            // Act
            var result = await ordersController.PostOrder(orderCreateRequest);

            // Assert
            var ordersResult = Assert.IsType <CreatedAtActionResult>(result.Result);
            Assert.NotNull(ordersResult.Value as Order);
        }
Example #17
0
        public async Task GetAll_Success()
        {
            // Arrange
            var dbContext   = _fixture.Context;
            var mapper      = MapperMock.Get();
            var fileService = FileServiceMock.FilesService();
            var product1    = NewDatas.NewProduct();

            dbContext.Products.Add(product1);
            dbContext.SaveChanges();

            var productsService    = new ProductService(dbContext, fileService, mapper);
            var productsController = new ProductsController(productsService, fileService);
            // Act
            var result = await productsController.GetProducts();

            // Assert
            Assert.IsType <OkObjectResult>(result.Result);
        }
    public async Task StubIntegration_RegularGet_File_HappyFlow()
    {
        // arrange
        const string fileContents = "File contents yo!";
        var          url          = $"{TestServer.BaseAddress}text.txt";

        FileServiceMock
        .Setup(m => m.FileExists("text.txt"))
        .Returns(true);
        FileServiceMock
        .Setup(m => m.ReadAllBytes("text.txt"))
        .Returns(Encoding.UTF8.GetBytes(fileContents));

        // act / assert
        using var response = await Client.GetAsync(url);

        var content = await response.Content.ReadAsStringAsync();

        Assert.AreEqual(fileContents, content);
        Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
    }
Example #19
0
        public void WhenExecuteCommandWithoutNewPathParameter_CommandManager_ShouldThrowException()
        {
            var oldPath           = "myOldPath";
            var storedDataService = new StoredDataServiceMock(false);

            var fileServiceMock   = new FileServiceMock();
            var commandDefinition = new RenameFolderCommand(fileServiceMock);
            var instance          = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathOldFolderParameter.GetInvokeName(),
                oldPath);

            Assert.Throws <InvalidParamsException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
Example #20
0
        public void WhenExecuteCommandWithoutPathParameter_CommandManager_ShouldThrowException()
        {
            string pipelineName = "myPipeline";

            var storedDataService = new StoredDataServiceMock();
            var fileService       = new FileServiceMock();
            var commandDefinition = new AddPipelineCommand(storedDataService, fileService);

            var instance = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandNameParameter.GetInvokeName(),
                pipelineName);

            Assert.Throws <InvalidParamsException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
        public void Setup()
        {
            _container = new MocksAndStubsContainer();

            _applicationSettings   = _container.ApplicationSettings;
            _context               = _container.UserContext;
            _repository            = _container.Repository;
            _pluginFactory         = _container.PluginFactory;
            _settingsService       = _container.SettingsService;
            _userService           = _container.UserService;
            _historyService        = _container.HistoryService;
            _pageService           = _container.PageService;
            _attachmentFileHandler = new AttachmentFileHandler(_applicationSettings, _container.FileService);
            _fileService           = _container.FileService as FileServiceMock;

            try
            {
                // Delete any existing attachments folder
                DirectoryInfo directoryInfo = new DirectoryInfo(_applicationSettings.AttachmentsFolder);
                if (directoryInfo.Exists)
                {
                    directoryInfo.Attributes = FileAttributes.Normal;
                    directoryInfo.Delete(true);
                }

                Directory.CreateDirectory(_applicationSettings.AttachmentsFolder);
            }
            catch (IOException e)
            {
                Assert.Fail("Unable to delete the attachments folder " + _applicationSettings.AttachmentsFolder + ", does it have a lock/explorer window open, or Mercurial open?" + e.ToString());
            }
            catch (ArgumentException e)
            {
                Assert.Fail("Unable to delete the attachments folder " + _applicationSettings.AttachmentsFolder + ", is EasyMercurial open?" + e.ToString());
            }

            _filesController  = new FileManagerController(_applicationSettings, _userService, _context, _settingsService, _attachmentFileHandler, _fileService);
            _mvcMockContainer = _filesController.SetFakeControllerContext();
        }
Example #22
0
        public void WhenExecuteCommandWithNonExistingTemplateConfigFile_CommandManager_ShouldThrowException()
        {
            var myPath      = @"my\Path";
            var fileService = new FileServiceMock()
            {
                ExistsTemplateConfigFileReturn = false, ExistsDirectoryReturn = true
            };
            var commandDefinition = new TemplateCommand(fileService, _storedDataService);

            var instance = new CommandManager(_loggerServiceMock, _storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathParameter.GetInvokeName(),
                myPath);

            Assert.Throws <TemplateConfigFileNotFoundException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
Example #23
0
        public void WhenExecuteCommandWithValidParameters_CommandManager_ShouldAddPipeline()
        {
            string pipelinePath      = "myPath";
            string pipelineName      = "myPipeline";
            var    storedDataService = new StoredDataServiceMock()
            {
                ExistsPipelineReturn = false
            };
            var fileService = new FileServiceMock()
            {
                ExistsFileReturn = true
            };
            var commandDefinition = new AddPipelineCommand(storedDataService, fileService);

            var instance = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathParameter.GetInvokeName(),
                pipelinePath,
                commandDefinition.CommandNameParameter.GetInvokeName(),
                pipelineName);

            instance.ExecuteInputRequest(inputRequest);

            var expectedPath = pipelinePath;
            var actualPath   = storedDataService.AddedPipelinePath;

            Assert.Equal(expectedPath, actualPath);

            var expectedName = pipelineName;
            var actualName   = storedDataService.AddedPipelineName;

            Assert.Equal(expectedName, actualName);
        }
Example #24
0
        public void WhenExecuteCommandWithInvalidFile_CommandManager_ShouldThrowException()
        {
            var path = "myPath";
            var storedDataService = new StoredDataServiceMock(false);

            var fileServiceMock = new FileServiceMock()
            {
                IsFileReturn = false
            };
            var commandDefinition = new UnzipCommand(fileServiceMock);
            var instance          = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathParameter.GetInvokeName(),
                path);

            Assert.Throws <InvalidZipFileException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
Example #25
0
        public void WhenExecuteCommandWithValidParams_CommandManager_ShouldExecuteReplace()
        {
            var newValue          = "myNewValue";
            var oldValue          = "myOldValue";
            var path              = "myPath";
            var storedDataService = new StoredDataServiceMock();

            var fileServiceMock   = new FileServiceMock();
            var commandDefinition = new ReplaceFileContentCommand(fileServiceMock);
            var instance          = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandNewValueParameter.GetInvokeName(),
                newValue,
                commandDefinition.CommandOldValueParameter.GetInvokeName(),
                oldValue,
                commandDefinition.CommandPathParameter.GetInvokeName(),
                path);

            instance.ExecuteInputRequest(inputRequest);

            var expectedPath     = path;
            var expectedOldValue = oldValue;
            var expectedNewValue = newValue;

            var actualPath     = fileServiceMock.ReplacedFilesContentsPath;
            var actualOldValue = fileServiceMock.ReplacedStringInPathsOldValue;
            var actualNewValue = fileServiceMock.ReplacedStringInPathsNewValue;

            Assert.Equal(expectedPath, actualPath);
            Assert.Equal(expectedOldValue, actualOldValue);
            Assert.Equal(expectedNewValue, actualNewValue);
        }
Example #26
0
        public async Task Put_Success(int quantity)
        {
            // Arrange
            var dbContext = _fixture.Context;
            var mapper    = MapperMock.Get();

            var fileService = FileServiceMock.FilesService();

            var user = NewDatas.NewUser();
            await dbContext.Users.AddAsync(user);

            await dbContext.SaveChangesAsync();

            var product1 = NewDatas.NewProduct();
            await dbContext.Products.AddRangeAsync(product1);

            await dbContext.SaveChangesAsync();

            #region create intial order data
            var order = NewDatas.NewOrder();
            dbContext.Orders.Add(order);
            await dbContext.SaveChangesAsync();

            var orderDetail1 = NewDatas.NewOrderDetail();
            orderDetail1.productId = product1.productId;
            orderDetail1.orderId   = order.orderId;

            int initialQuantity = orderDetail1.quantity;

            await dbContext.OrderDetails.AddRangeAsync(orderDetail1);

            await dbContext.SaveChangesAsync();

            order.orderDetails = new List <OrderDetail> {
                orderDetail1
            };
            order.user = user;
            await dbContext.SaveChangesAsync();

            #endregion

            var orderCreateRequest = NewDatas.NewOrderDetailRequest();
            orderCreateRequest.productId = product1.productId;
            orderCreateRequest.quantity  = quantity;

            int afterPostQuantity = quantity;

            var ordersService    = new OrderService(dbContext, mapper);
            var ordersController = new OrdersController(ordersService, mapper, fileService);

            #region set controller user
            ordersController.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
                    {
                        new Claim(ClaimTypes.Name, user.UserName),
                        new Claim(ClaimTypes.NameIdentifier, user.Id.ToString(CultureInfo.InvariantCulture))
                    }, "Bearer")
                                               )
                }
            };
            #endregion

            // Act
            var result = await ordersController.PostOrder(orderCreateRequest);

            // Assert
            var ordersResult         = Assert.IsType <CreatedAtActionResult>(result.Result);
            var productInOrderResult = (ordersResult.Value as Order).orderDetails.First(x => x.productId == product1.productId);
            Assert.Equal(productInOrderResult.quantity, initialQuantity + afterPostQuantity);
        }
Example #27
0
        /// <summary>
        /// Creates a new instance of MocksAndStubsContainer.
        /// </summary>
        /// <param name="useCacheMock">The 'Roadkill' MemoryCache is used by default, but as this is static it can have problems with
        /// the test runner unless you clear the Container.MemoryCache on setup each time, but then doing that doesn't give a realistic
        /// reflection of how the MemoryCache is used inside an ASP.NET environment.</param>
        public MocksAndStubsContainer(bool useCacheMock = false)
        {
            ApplicationSettings                   = new ApplicationSettings();
            ApplicationSettings.Installed         = true;
            ApplicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "attachments");
            ConfigReaderWriter = new ConfigReaderWriterStub();

            // Cache
            MemoryCache        = useCacheMock ? new CacheMock() : CacheMock.RoadkillCache;
            ListCache          = new ListCache(ApplicationSettings, MemoryCache);
            SiteCache          = new SiteCache(MemoryCache);
            PageViewModelCache = new PageViewModelCache(ApplicationSettings, MemoryCache);

            // Repositories
            SettingsRepository = new SettingsRepositoryMock();
            SettingsRepository.SiteSettings            = new SiteSettings();
            SettingsRepository.SiteSettings.MarkupType = "Creole";
            UserRepository      = new UserRepositoryMock();
            PageRepository      = new PageRepositoryMock();
            InstallerRepository = new InstallerRepositoryMock();

            RepositoryFactory = new RepositoryFactoryMock()
            {
                SettingsRepository  = SettingsRepository,
                UserRepository      = UserRepository,
                PageRepository      = PageRepository,
                InstallerRepository = InstallerRepository
            };
            DatabaseTester = new DatabaseTesterMock();

            // Plugins
            PluginFactory   = new PluginFactoryMock();
            MarkupConverter = new MarkupConverter(ApplicationSettings, SettingsRepository, PageRepository, PluginFactory);

            // Services
            // Dependencies for PageService. Be careful to make sure the class using this Container isn't testing the mock.
            SettingsService            = new SettingsService(RepositoryFactory, ApplicationSettings);
            UserService                = new UserServiceMock(ApplicationSettings, UserRepository);
            UserContext                = new UserContext(UserService);
            SearchService              = new SearchServiceMock(ApplicationSettings, SettingsRepository, PageRepository, PluginFactory);
            SearchService.PageContents = PageRepository.PageContents;
            SearchService.Pages        = PageRepository.Pages;
            HistoryService             = new PageHistoryService(ApplicationSettings, SettingsRepository, PageRepository, UserContext,
                                                                PageViewModelCache, PluginFactory);
            FileService = new FileServiceMock();
            PageService = new PageService(ApplicationSettings, SettingsRepository, PageRepository, SearchService, HistoryService,
                                          UserContext, ListCache, PageViewModelCache, SiteCache, PluginFactory);

            StructureMapContainer = new Container(x =>
            {
                x.AddRegistry(new TestsRegistry(this));
            });

            Locator = new StructureMapServiceLocator(StructureMapContainer, false);

            InstallationService = new InstallationService((databaseName, connectionString) =>
            {
                InstallerRepository.DatabaseName     = databaseName;
                InstallerRepository.ConnectionString = connectionString;

                return(InstallerRepository);
            }, Locator);

            // EmailTemplates
            EmailClient = new EmailClientMock();
        }