Example #1
0
        public async Task HandleShouldReturnOk()
        {
            // Arrange
            var id      = Guid.NewGuid();
            var version = 1;

            var userCreated           = "anyUserCreated";
            var operation             = "TestOperation";
            var operationalDepartment = "any";
            var site = "any";


            var logAsMock = new Mock <ILogAs>();

            logAsMock.Setup(x => x.Error(It.IsAny <string>(), It.IsAny <Exception>()));
            var logAs = logAsMock.Object;

            var workOrderRepositoryMock = new Mock <IWorkOrderWriteRepository>();

            workOrderRepositoryMock.Setup(x => x.CreateAsync(It.IsAny <WorkOrder>())).Returns(Task.CompletedTask);
            var workOrderRepository = workOrderRepositoryMock.Object;

            var identifierProviderMock = new Mock <IIdentifierProvider>();

            identifierProviderMock.Setup(x => x.Generate()).Returns(id);
            var identifierProvider = identifierProviderMock.Object;

            var versionProviderMock = new Mock <IVersionProvider>();

            versionProviderMock.Setup(x => x.Generate()).Returns(version);
            var versionProvider = versionProviderMock.Object;

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();

            dateTimeProviderMock.Setup(x => x.Parse(It.IsAny <string>())).Returns(DateTime.UtcNow);
            var dateTimeProvider = dateTimeProviderMock.Object;

            var command = new CreateWorkOrderCommand(userCreated, site, operation, operationalDepartment);

            var handler = new CreateWorkOrderCommandHandler(logAs, workOrderRepository, identifierProvider, versionProvider, dateTimeProvider);

            // Act
            var result = await handler.Handle(command, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeFalse();
            result.Should().BeOfType(typeof(Result <Guid>));
        }
Example #2
0
        public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs()
        {
            // Arrange
            var id      = Guid.NewGuid();
            var version = 1;

            var userCreated           = "anyUserCreated";
            var operation             = "TestOperation";
            var operationalDepartment = "any";
            var site = "any";

            var logAsMock = new Mock <ILogAs>();

            logAsMock.Setup(x => x.Error(It.IsAny <string>(), It.IsAny <Exception>()));
            var logAs = logAsMock.Object;

            var workOrderRepositoryMock = new Mock <IWorkOrderWriteRepository>();

            workOrderRepositoryMock.Setup(x => x.CreateAsync(It.IsAny <WorkOrder>())).Throws <SomeDatabaseSpecificException>();
            var workOrderRepository = workOrderRepositoryMock.Object;

            var identifierProviderMock = new Mock <IIdentifierProvider>();

            identifierProviderMock.Setup(x => x.Generate()).Returns(id);
            var identifierProvider = identifierProviderMock.Object;

            var versionProviderMock = new Mock <IVersionProvider>();

            versionProviderMock.Setup(x => x.Generate()).Returns(version);
            var versionProvider = versionProviderMock.Object;

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();

            dateTimeProviderMock.Setup(x => x.Parse(It.IsAny <string>())).Returns(DateTime.UtcNow);
            var dateTimeProvider = dateTimeProviderMock.Object;

            var command = new CreateWorkOrderCommand(userCreated, site, operation, operationalDepartment);

            var handler = new CreateWorkOrderCommandHandler(logAs, workOrderRepository, identifierProvider, versionProvider, dateTimeProvider);

            // Act
            var result = await handler.Handle(command, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.CreateWorkOrderFailure);
        }