public async Task Create_Author_Should_Call_Add_Method_And_SaveChanges_Once() { //Arrange var fixture = new Fixture(); var command = fixture.For <CreateAuthorWithDeathDateCommand>() .With(x => x.DateOfBirth, DateTimeOffset.Now.AddDays(-2)) .With(x => x.DateOfDeath, DateTimeOffset.Now.AddDays(-1)) .Create(); var mockUnitOfWork = new Mock <IUnitOfWork>(); var mockAuthorRepository = new Mock <IAsyncRepository <Author> >(); mockUnitOfWork.Setup(x => x.AuthorRepository).Returns(mockAuthorRepository.Object); var addAuthorHandler = new AddCommandHandler(mockUnitOfWork.Object); //Act var result = await addAuthorHandler.Handle(command); //Assert mockAuthorRepository.Verify(x => x.AddAsync(It.IsAny <Author>()), Times.Once); mockUnitOfWork.Verify(x => x.SaveChangesAsync(), Times.Once); result.IsSuccess.Should().BeTrue(); result.Value.Name.First.Should().Be(command.FirstName); result.Value.Name.Last.Should().Be(command.LastName); result.Value.DateOfBirth.Value.Should().Be(command.DateOfBirth); result.Value.MainCategory.Value.Should().Be(command.MainCategory); result.Value.DateOfDeath.Value.Value.Should().Be(command.DateOfDeath); }
public AddCommand(IServiceProvider serviceProvider) : base("add") { Description = "Adds a to do item."; AddArgument(GetSubjectArgument()); Handler = AddCommandHandler.Create(serviceProvider); }
public async Task AddCommandIgnoresInvalidCommand() { var sourceControl = Substitute.For <ISourceControl>(); var target = new AddCommandHandler(sourceControl); dynamic command = new System.Dynamic.ExpandoObject(); command.Type = "Invalid"; await HandleCommand(target, command); await sourceControl.DidNotReceive().Add(Arg.Any <string>()); }
public async Task AddCommandHandlesValidCommand() { var sourceControl = Substitute.For <ISourceControl>(); var target = new AddCommandHandler(sourceControl); dynamic command = new System.Dynamic.ExpandoObject(); command.Type = "Add"; command.Path = "Path"; await HandleCommand(target, command); await sourceControl.Received().Add("Path"); }
public void HandleCommand_ShouldAddTaskToRepository() { // Arrange var taskRepository = new InMemoryTaskRepository(); var addCommandHandler = new AddCommandHandler(taskRepository); // Act addCommandHandler.HandleCommand(new AddCommand("tasktitle")); // Assert Assert.That(taskRepository.GetAll(), Is.Not.Empty); }
public void HandleCommand_ShouldAddTaskWithTitle() { // Arrange const string taskTitle = "tasktitle"; var taskRepository = new InMemoryTaskRepository(); var addCommandHandler = new AddCommandHandler(taskRepository); // Act addCommandHandler.HandleCommand(new AddCommand(taskTitle)); // Assert Assert.That(taskRepository.GetAll().First().Title, Is.EqualTo(taskTitle)); }
public void HandleCommand_NoExistingTasksShouldAddTaskNumberOne() { // Arrange const string taskTitle = "tasktitle"; var taskRepository = new InMemoryTaskRepository(); var addCommandHandler = new AddCommandHandler(taskRepository); // Act addCommandHandler.HandleCommand(new AddCommand(taskTitle)); // Assert Assert.That(taskRepository.GetAll().Last().Number, Is.EqualTo(1)); }
public async Task Create_Author_With_Same_BirthDate_And_DeathDate_Should_Fail_With_Error() { //Arrange var fixture = new Fixture(); fixture.Inject(DateTimeOffset.Now.AddDays(-fixture.Create <int>())); var command = fixture.Create <CreateAuthorWithDeathDateCommand>(); var mockUnitOfWork = new Mock <IUnitOfWork>(); var addAuthorHandler = new AddCommandHandler(mockUnitOfWork.Object); //Act var result = await addAuthorHandler.Handle(command); //Assert result.IsFailure.Should().BeTrue(); result.Error.Should().Be("Death date should not be less than birth date."); }
public void Should_ShowWarning_When_ItemIsInvalid() { var viewClosed = false; var item = new Item(); var parent = Substitute.For <Item>(); var command = new AddCommand(item, parent, () => { viewClosed = true; }); var handler = new AddCommandHandler(_settingsStore, _jobScheduler, _usageReporter, _dialogService); handler.Handle(command); Assert.IsFalse(viewClosed); _dialogService.Received().ShowWarning(Arg.Any <string>(), Arg.Any <string>()); parent.DidNotReceive().Add(item); _settingsStore.DidNotReceive().TrySave(); _jobScheduler.DidNotReceive().Schedule(item); _usageReporter.DidNotReceive().ReportEvent(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()); }
public void Should_AddToParentScheduleAndSave() { //todo: separate tests var viewClosed = false; var item = new Item { Name = "Test" }; var parent = Substitute.For <Item>(); var command = new AddCommand(item, parent, () => { viewClosed = true; }); var handler = new AddCommandHandler(_settingsStore, _jobScheduler, _usageReporter, _dialogService); handler.Handle(command); Assert.IsTrue(viewClosed); Assert.IsTrue(item.IsSelected); parent.Received().Add(item); _settingsStore.Received(1).TrySave(); _jobScheduler.Received(1).Schedule(item); _usageReporter.Received(1).ReportEvent("Items", "Add", command.Item.GetType().Name); }
public CalculatorResponse ExecuteAdd(string input) { var add = new AddCommandHandler(input, _logger); return(add.Handle()); }
public void Should_Throw_When_Command_Is_Null() { var handler = new AddCommandHandler(_settingsStore, _jobScheduler, _usageReporter, _dialogService); handler.Handle(null); }