public void AddExistingDefaultRemarkShouldNotModifyCollection() { // Arrange var entity = new Remark(id, name, nameOnApplication, description, icon); var defaultRemark = new DefaultRemark(Guid.NewGuid().ToString()); entity.AddDefaultRemark(defaultRemark); // Act entity.AddDefaultRemark(defaultRemark); // Assert entity.DefaultRemarks.Count.Should().Be(1); entity.DefaultRemarks.ElementAt(0).Should().Be(defaultRemark); }
public static Remark CreateRemark(Guid id, string name, string nameOnApplication, string description, RemarkIcon icon, IEnumerable <DefaultRemark> defaultRemarks, IEnumerable <Tag> tags) { // prepare var writeRepository = new RemarkWriteRepository(new DataContext(new PersistenceConfiguration(RepositoryTestsHelper.ConnectionString))); var readRepository = new RemarkReadRepository(new DataContext(new PersistenceConfiguration(RepositoryTestsHelper.ConnectionString))); // create var remark = new Remark(id, name, nameOnApplication, description, icon); foreach (var defaultRemark in defaultRemarks) { remark.AddDefaultRemark(defaultRemark); } foreach (var tag in tags) { remark.AddTag(tag); } writeRepository.CreateAsync(remark).GetAwaiter().GetResult(); // result var result = readRepository.GetAsync(id).Result; return(result); }
public void ClearDefaultRemarksShouldSucceed() { // Arrange var entity = new Remark(id, name, nameOnApplication, description, icon); var defaultRemark = new DefaultRemark(Guid.NewGuid().ToString()); entity.AddDefaultRemark(defaultRemark); // Act entity.ClearDefaultRemarks(); // Assert entity.DefaultRemarks.Count.Should().Be(0); }
public void RemoveUnexistingDefaultRemarkShouldPassSilentlyWithoutAnyImpactOnCollection() { // Arrange var entity = new Remark(id, name, nameOnApplication, description, icon); var defaultRemark = new DefaultRemark(Guid.NewGuid().ToString()); entity.AddDefaultRemark(defaultRemark); var defaultRemarkToRemove = new DefaultRemark(Guid.NewGuid().ToString()); // Act entity.RemoveDefaultRemark(defaultRemarkToRemove); // Assert entity.DefaultRemarks.Count.Should().Be(1); entity.DefaultRemarks.ElementAt(0).Should().Be(defaultRemark); }
public async Task CreateShouldSuccess() { // Arrange var id = Guid.NewGuid(); var name = "name"; var nameOnApplication = "nameOnApplication"; var description = "description"; var icon = new RemarkIcon(Guid.NewGuid()); var defaultRemark = new DefaultRemark("defaultRemark1"); var defaultRemarks = new List <DefaultRemark>() { defaultRemark }; var tag = new Tag("tag1"); var tags = new List <Tag>() { tag }; var remark = new Remark(id, name, nameOnApplication, description, icon); defaultRemarks.ForEach(x => remark.AddDefaultRemark(x)); tags.ForEach(x => remark.AddTag(x)); // Act await _repository.CreateAsync(remark); // Assert var data = RepositoryHelper.ForRemark.GetRemarks(); data.Should().HaveCount(1); var result = data.First(); result.Name.Should().Be(name); result.NameOnApplication.Should().Be(nameOnApplication); result.Description.Should().Be(description); result.Icon.Should().Be(icon); result.DefaultRemarks.Should().HaveCount(1); result.DefaultRemarks.First().Should().Be(defaultRemark); result.Tags.Should().HaveCount(1); result.Tags.First().Should().Be(tag); }
public void CreateShouldSuccess() { // Arrange // Act var result = new Remark(id, name, nameOnApplication, description, icon); tags.ForEach(x => result.AddTag(x)); defaultRemarks.ForEach(x => result.AddDefaultRemark(x)); // Assert result.Should().NotBeNull(); result.Tags.Should().AllBeOfType(typeof(Tag)); result.DefaultRemarks.Should().AllBeOfType(typeof(DefaultRemark)); result.Name.Should().Be(name); result.Id.Should().Be(id); result.Description.Should().Be(description); result.Icon.Should().Be(icon); }
public async Task <Result> Handle(CreateRemarkCommand request, CancellationToken cancellationToken) { var id = _identifierProvider.Generate(); var remarkToCreate = new Remark(id, request.Name, request.NameOnApplication, request.Description, new RemarkIcon(request.Icon)); request.Tags.ToList().ForEach(x => remarkToCreate.AddTag(new Tag(x))); request.DefaultRemarks.ToList().ForEach(x => remarkToCreate.AddDefaultRemark(new DefaultRemark(x))); remarkToCreate.Version = _versionProvider.Generate(); Result result; try { await _remarkWriteRepository.CreateAsync(remarkToCreate); result = Result.Ok(id, remarkToCreate.Version); } catch (UniqueKeyException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.Conflict.Name, Message = HandlerFailures.Conflict, Target = "name" } } ); } catch { result = Result.Fail(CustomFailures.CreateRemarkFailure); } return(result); }
public async Task <Result> Handle(UpdateRemarkCommand request, CancellationToken cancellationToken) { Result result; try { var icon = await _remarkReadRepository.GetAsync(request.Id); if (icon.Version != request.Version) { throw new CommandVersionException(); } var updatedRemark = new Remark(request.Id, request.Name, request.NameOnApplication, request.Description, new RemarkIcon(request.Icon)); request.Tags.ToList().ForEach(x => updatedRemark.AddTag(new Tag(x))); request.DefaultRemarks.ToList().ForEach(x => updatedRemark.AddDefaultRemark(new DefaultRemark(x))); updatedRemark.Version = _versionProvider.Generate(); await _remarkWriteRepository.UpdateAsync(updatedRemark); result = Result.Ok(updatedRemark.Version); } catch (EntityNotFoundDbException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotFound.Name, Message = string.Format(HandlerFailures.NotFound, "Remark"), Target = "id" } } ); } catch (CommandVersionException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotMet.Name, Message = HandlerFailures.NotMet, Target = "version" } } ); } catch (UniqueKeyException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.Conflict.Name, Message = HandlerFailures.Conflict, Target = "name" } } ); } catch { result = Result.Fail(CustomFailures.UpdateRemarkFailure); } return(result); }