public static void CreateGeometry(IMinecraftCommandService commandService, params string[] args) { var position = commandService.GetLocation(); var lines = new CreateCommandHandler(commandService).Handle(args.ToList().Skip(1).ToArray(), position, new List <SavedPosition>()); if (lines.Any()) { var _commandFormater = commandService.GetFormater(); var sw = new Stopwatch(); sw.Start(); var lastLine = lines.First(); foreach (var line in lines) { if (lastLine.Start.Distance2D(line.Start) > 100) { commandService.Command($"tp @s {line.Start.X} ~ {line.Start.Z}"); } var command = _commandFormater.Fill(line.Start.X, line.Start.Y, line.Start.Z, line.End.X, line.End.Y, line.End.Z, line.Block, line.Block.Contains(" ")?"":"0"); commandService.Command(command); lastLine = line; } sw.Stop(); commandService.Status($"time to queue commands {sw.Elapsed.TotalSeconds}"); //Console.WriteLine($"time to queue commands {sw.Elapsed.TotalSeconds}"); sw.Reset(); sw.Start(); commandService.Wait(); sw.Stop(); commandService.Status($"time to complete import {sw.Elapsed.TotalSeconds}"); //Console.WriteLine($"time to complete import {sw.Elapsed.TotalSeconds}"); } }
public async Task throws_when_aggregate_not_found(CreateCalendarItemCommand createCommand, DeleteCalendarItemCommand deleteCommand) { createCommand.EndDate = createCommand.StartDate.AddDays(1); await CreateCommandHandler.HandleAsync(createCommand); var exception = await Record.ExceptionAsync(() => act(deleteCommand)); exception.ShouldBeOfType(typeof(AwesomeCalendarException)); }
public void Success() { var command = new CreateCommand("A", 19); var handler = new CreateCommandHandler(new List <ICommandBaseValidator <CreateCommand, CreateCommandData> > { new CreateCommandValidatorAge(), new CreateCommandValidatorName() }); var response = handler.Execute(command); response.Success.Should().Be(true); }
public void Fail_One_Error() { var command = new CreateCommand("A", 17); var handler = new CreateCommandHandler(new List <ICommandBaseValidator <CreateCommand, CreateCommandData> > { new CreateCommandValidatorAge(), new CreateCommandValidatorName() }); var response = handler.Execute(command); response.Success.Should().Be(false); response.ValidatorResponses.Count.Should().Be(1); }
public void CreateCommandHandlerOnSuccessHasValidDirectoryStructure() { var mockFileSystem = new MockFileSystem(); mockFileSystem.AddDirectory(Environment.CurrentDirectory); var globalTuple = MockFileSystemHelper.GetGlobalTemplateMock(); mockFileSystem.AddFile(globalTuple.Item1, globalTuple.Item2); var localTuple = MockFileSystemHelper.GetLocalTemplateMock(); mockFileSystem.AddFile(localTuple.Item1, localTuple.Item2); var configComposer = new ConfigComposer(mockFileSystem); var contentComposer = new ContentComposer(mockFileSystem); var handler = new CreateCommandHandler( configComposer, contentComposer, mockFileSystem, _mockTerminal.Object); const string projectName = "MyUnitTestProject"; const string outputDirectoryName = "public"; handler.Handle(new CreateCommand { OutputDirectoryName = outputDirectoryName, ProjectName = projectName }); string projectRootPath = mockFileSystem.Path.Combine( Environment.CurrentDirectory, projectName); string projectOutputPath = mockFileSystem.Path.Combine( projectRootPath, outputDirectoryName); string projectContentPath = mockFileSystem.Path.Combine( projectRootPath, ReservedDirectories.ContentDirectoryName); Assert.Multiple(() => { Assert.True(mockFileSystem.Directory.Exists(projectRootPath)); Assert.True(mockFileSystem.Directory.Exists(projectOutputPath)); Assert.True(mockFileSystem.Directory.Exists(projectContentPath)); }); }
public void Init() { _mockLogger = new Mock <ILogger>(); _mockLoggerFactory = new Mock <ILoggerFactory>(); _mockLoggerFactory.Setup(x => x.GetLogger(It.IsAny <object>())).Returns(_mockLogger.Object); _mockDispatcher = new Mock <IDispatcher>(); _mockProductRepository = new Mock <IRepository <Models.Product> >(); _sut = new CreateCommandHandler( _mockLoggerFactory.Object, _mockDispatcher.Object, _mockProductRepository.Object); }
public async Task HandleShouldFailWhenRecordWithSameLoginAlreadyExist() { // Arrange var id = Guid.NewGuid(); var version = 1; var login = "******"; var password = "******"; var firstName = "FirstName"; var lastName = "LastName"; var userRepositoryMock = new Mock <IUserRepository>(); userRepositoryMock.Setup(x => x.Create(It.IsAny <User>())).Throws <UniqueKeyException>(); var userRepository = userRepositoryMock.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 passwordProviderMock = new Mock <IPasswordProvider>(); passwordProviderMock.Setup(x => x.Hash(It.IsAny <string>())).Returns("hashedPassword"); var passwordProvider = passwordProviderMock.Object; var publishIntegrationEventsServiceMock = new Mock <IPublishIntegrationEventsService>(); publishIntegrationEventsServiceMock.Setup(x => x.PublishUserCreated(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())); var publishIntegrationEventsService = publishIntegrationEventsServiceMock.Object; var command = new CreateCommand(login, password, firstName, lastName); var handler = new CreateCommandHandler(userRepository, identifierProvider, versionProvider, passwordProvider, publishIntegrationEventsService); // Act var result = await handler.Handle(command, CancellationToken.None); // Assert result.Failures.Should().OnlyContain(x => x.Code == HandlerFaultCode.Conflict.Name && x.Message == HandlerFailures.Conflict && x.Target == "login"); }
public async Task Handle_ShouldPersistCategory() { var command = new CreateCommand { Name = "General Clothes", Disabled = false }; var handler = new CreateCommandHandler(Context); var result = await handler.Handle(command, CancellationToken.None); var entity = Context.Categories.Find(result); entity.ShouldNotBeNull(); entity.Name.ShouldBe(command.Name); }
public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs() { // Arrange var id = Guid.NewGuid(); var version = 1; var login = "******"; var password = "******"; var firstName = "FirstName"; var lastName = "LastName"; var userRepositoryMock = new Mock <IUserRepository>(); userRepositoryMock.Setup(x => x.Create(It.IsAny <User>())).Throws <SomeDatabaseSpecificException>(); var userRepository = userRepositoryMock.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 passwordProviderMock = new Mock <IPasswordProvider>(); passwordProviderMock.Setup(x => x.Hash(It.IsAny <string>())).Returns("hashedPassword"); var passwordProvider = passwordProviderMock.Object; var publishIntegrationEventsServiceMock = new Mock <IPublishIntegrationEventsService>(); publishIntegrationEventsServiceMock.Setup(x => x.PublishUserCreated(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())); var publishIntegrationEventsService = publishIntegrationEventsServiceMock.Object; var command = new CreateCommand(login, password, firstName, lastName); var handler = new CreateCommandHandler(userRepository, identifierProvider, versionProvider, passwordProvider, publishIntegrationEventsService); // Act var result = await handler.Handle(command, CancellationToken.None); // Assert result.IsFailure.Should().BeTrue(); result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.CreateUserFailure); }
public async Task HandleShouldReturnOk() { // Arrange var id = Guid.NewGuid(); var version = 1; var login = "******"; var password = "******"; var firstName = "FirstName"; var lastName = "LastName"; var userRepositoryMock = new Mock <IUserRepository>(); userRepositoryMock.Setup(x => x.Create(It.IsAny <User>())).Returns(Task.CompletedTask); var userRepository = userRepositoryMock.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 passwordProviderMock = new Mock <IPasswordProvider>(); passwordProviderMock.Setup(x => x.Hash(It.IsAny <string>())).Returns("hashedPassword"); var passwordProvider = passwordProviderMock.Object; var publishIntegrationEventsServiceMock = new Mock <IPublishIntegrationEventsService>(); publishIntegrationEventsServiceMock.Setup(x => x.PublishUserCreated(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.CompletedTask); var publishIntegrationEventsService = publishIntegrationEventsServiceMock.Object; var command = new CreateCommand(login, password, firstName, lastName); var handler = new CreateCommandHandler(userRepository, identifierProvider, versionProvider, passwordProvider, publishIntegrationEventsService); // Act var result = await handler.Handle(command, CancellationToken.None); // Assert result.IsFailure.Should().BeFalse(); result.Should().BeOfType(typeof(Result <Guid>)); }
private void HandleCreateCommand(string[] commandArgs, MinecraftCommandService minecraft, Position position, List <SavedPosition> storaedPositions) { var lines = new CreateCommandHandler().Handle(commandArgs, minecraft, position, storaedPositions); var sw = new Stopwatch(); sw.Start(); foreach (var line in lines) { minecraft.Command($"fill?from={line.Start.X} {line.Start.Y} {line.Start.Z}&to={line.End.X} {line.End.Y} {line.End.Z}&tileName={line.Block}&tileData=0"); } sw.Stop(); minecraft.Status($"time to queue commands {sw.Elapsed.TotalSeconds}"); Console.WriteLine($"time to queue commands {sw.Elapsed.TotalSeconds}"); sw.Reset(); sw.Start(); minecraft.Wait(); sw.Stop(); minecraft.Status($"time to complete import {sw.Elapsed.TotalSeconds}"); Console.WriteLine($"time to complete import {sw.Elapsed.TotalSeconds}"); }
public async Task Handle_ShouldPersistTodoItem() { var command = new CreateCommand { Name = "TShirt", SellingPrice = 90, Description = "Description ..", BarCode = "ABC_000001", CategoryId = 1, Disabled = false }; var handler = new CreateCommandHandler(Context); var result = await handler.Handle(command, CancellationToken.None); var entity = Context.Products.Find(result); entity.ShouldNotBeNull(); entity.Name.ShouldBe(command.Name); }
public void CreateCommandHandlerOnSucessHasValidSettingsFile() { // TODO: validate actual JSON content - not just that the file exists. var mockFileSystem = new MockFileSystem(); mockFileSystem.AddDirectory(Environment.CurrentDirectory); var globalTuple = MockFileSystemHelper.GetGlobalTemplateMock(); mockFileSystem.AddFile(globalTuple.Item1, globalTuple.Item2); var localTuple = MockFileSystemHelper.GetLocalTemplateMock(); mockFileSystem.AddFile(localTuple.Item1, localTuple.Item2); var configComposer = new ConfigComposer(mockFileSystem); var contentComposer = new ContentComposer(mockFileSystem); var handler = new CreateCommandHandler( configComposer, contentComposer, mockFileSystem, _mockTerminal.Object); const string projectName = "MyUnitTestProject"; handler.Handle(new CreateCommand { OutputDirectoryName = "public", ProjectName = projectName }); string projectRootPath = mockFileSystem.Path.Combine( Environment.CurrentDirectory, projectName); Assert.True(mockFileSystem.File.Exists(mockFileSystem.Path.Combine( projectRootPath, "local-config.json"))); }
public void CreateCommandHandlerOnSuccessInformsUserOfActionsPerformed() { var mockFileSystem = new MockFileSystem(); mockFileSystem.AddDirectory(Environment.CurrentDirectory); var mockConfigComposer = new Mock <IConfigComposer>(); var mockContentComposer = new Mock <IContentComposer>(); var handler = new CreateCommandHandler( mockConfigComposer.Object, mockContentComposer.Object, mockFileSystem, _mockTerminal.Object); handler.Handle(new CreateCommand { OutputDirectoryName = "public", ProjectName = "MyUnitTestProject" }); _mockTerminal.Verify(mock => mock.RenderText(It.IsAny <string>()), Times.Exactly(2)); }
public async Task Apply_ValidParams_AccountRootCreated() { //Arrange var id = Guid.Parse("4fc67e9a-1eec-4d08-9a38-3114a2ad07ba"); var userId = Guid.Parse("c3216c1c-bef6-4a6a-ada7-06c038aa0da3"); var month = 9; var year = 2020; var currency = "EUR"; var accountDto = new CreateAccountDto { Currency = currency, Id = id, Month = month, Year = year, OwnerId = userId }; var command = new CreateCommand(accountDto); var mockRepo = new Mock <IRepository <AccountRoot> >(); mockRepo.Setup(x => x.Save(It.IsAny <AccountRoot>())).Verifiable(); var mockMediater = new Mock <IMediator>(); mockMediater.Setup(x => x.Publish(It.IsAny <INotification>(), It.IsAny <CancellationToken>())); var createCommandHandler = new CreateCommandHandler(mockRepo.Object, mockMediater.Object); //Act await createCommandHandler.Handle(command, CancellationToken.None); //Assert mockRepo.Verify(); }
public CreateCommandHandlerTest() { _activitiesRepository = Substitute.For <IActivitiesRepository>(); _handler = new CreateCommandHandler(_activitiesRepository); }