public Speech(Title title, UrlValue urlValue, Description description, SpeechType type) { _title = title?.Value ?? throw new ArgumentNullAggregateException(0, nameof(title)); _url = urlValue?.Value ?? throw new ArgumentNullAggregateException(0, nameof(urlValue)); _description = description?.Value ?? throw new ArgumentNullAggregateException(0, nameof(description)); _type = type != null ? type.IntValue : throw new ArgumentNullAggregateException(0, nameof(type)); _mediaFileItems = new List <MediaFile>(); AddDomainEvent(new SpeechCreatedEvent(Id, Title.Value, Url.Value, Description.Value, new Command.SharedKernel.Events.SpeechTypeEnum(type.IntValue, type.StringValue))); }
public SpeechCreatedEvent(Guid id, Title title, UrlValue url, Description description, SpeechType type) { AggregateId = id; Title = title; Url = url; Description = description; Type = type; }
public Speech(Title title, UrlValue urlValue, Description description, SpeechType type) { Title = title ?? throw new ArgumentNullAggregateException(nameof(title)); Url = urlValue ?? throw new ArgumentNullAggregateException(nameof(urlValue)); Description = description ?? throw new ArgumentNullAggregateException(nameof(description)); Type = type ?? throw new ArgumentNullAggregateException(nameof(type)); _mediaFileItems = new List <MediaFile>(); AddDomainEvent(new SpeechCreatedEvent(Id, Title, Url, Description, Type)); }
public void EqualityIsTrueWhenObjectsAreSameValuesTest() { //Arrange var url1 = new UrlValue("http://url.com"); var url2 = new UrlValue("http://url.com"); Assert.Equal(url1, url2); Assert.True(url1.Equals(url2)); Assert.True(url1.Equals((object)url2)); Assert.Equal(url1.GetHashCode(), url2.GetHashCode()); }
public void CreateMediaWithNullMediaFile(SpeechType speechType) { //Arrange var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url.com"); //Act var speech = new SpeechAggregate.Speech(title, url, description, speechType); //Assert Assert.Throws <ArgumentNullAggregateException>(() => speech.CreateMedia(null, 0)); }
public void EqualityIsFalseWhenObjectsAreDifferentIdentitiesTest() { //Arrange var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url.com"); //Act var speech1 = new SpeechAggregate.Speech(Guid.NewGuid(), title, url, description, SpeechType.Conferences); var speech2 = new SpeechAggregate.Speech(Guid.NewGuid(), title, url, description, SpeechType.Conferences); Assert.False(speech1 == speech2); }
public void RegisterSpeechWithInvalidTypeThrowsDomainException() { //Arrange var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url.com"); //Act //Assert Assert.Throws <InvalidEnumAggregateException>(() => new SpeechAggregate.Speech(title, url, description, new SpeechType("patati"))); }
public void ApplySpeechDeletedEventWithInvalidAggregateIdShouldRaiseInvalidDomainEventException() { //Arrange var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description(@"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url.com"); var speech = new SpeechAggregate.Speech(title, url, description, SpeechType.Conferences); //Act //Assert Assert.Throws <InvalidDomainEventException>(() => speech.Apply(new SpeechDeletedEvent(Guid.NewGuid(), It.IsAny <bool>()))); }
public void CreateMediaWithInvalidVersion() { //Arrange var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url.com"); var file = new MediaFile(Guid.NewGuid(), new UrlValue( "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE2ybMU?ver=c5fc&q=90&m=6&h=201&w=358&b=%23FFFFFFFF&l=f&o=t&aim=true")); //Act var speech = new SpeechAggregate.Speech(title, url, description, SpeechType.Conferences); Assert.Throws <ConcurrencyException>(() => speech.CreateMedia(file, -1)); }
public void ChangeUrlWhenUrlIsNullOrEmptyShouldRaiseArgumentNullAggregateException(string newUrl) { //Arrange var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description(@"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url_new.com"); var speech = new SpeechAggregate.Speech(title, url, description, SpeechType.Conferences); //Act //Assert Assert.Throws <InvalidLenghtAggregateException>(() => speech.ChangeUrl(new UrlValue(newUrl), It.IsAny <long>())); }
public void DeleteSpeechWhenExpectedVersionIsNotEqualsToAggregateVersionShouldRaiseConcurrencyException() { //Arrange long expectedVersion = 1; var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description(@"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url.com"); var speech = new SpeechAggregate.Speech(title, url, description, SpeechType.Conferences); //Act //Assert Assert.Throws <ConcurrencyException>(() => speech.Delete(It.IsAny <Guid>(), expectedVersion)); }
public void RegisterSpeechWithValidDataReturnsSuccess(SpeechType speechType) { //Arrange var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url.com"); //Act var speech = new SpeechAggregate.Speech(title, url, description, speechType); //Assert Assert.Equal(title.Value, speech.Title.Value); Assert.Equal(description.Value, speech.Description.Value); Assert.Equal(url.Value, speech.Url.Value); Assert.Equal(speechType.Value, speech.Type.Value); }
public async Task Handle(RegisterSpeechCommandMessage command) { if (command == null) { throw new ApplicationArgumentNullException(nameof(command)); } var title = new Title(command.Title); var urlValue = new UrlValue(command.Url); var description = new Description(command.Description); var type = new SpeechType(command.Type); var speech = new Domain.SpeechAggregate.Speech(title, urlValue, description, type); await _speechRepository.CreateAsync(speech); _unitOfWork.Commit(); }
public async Task Handle(RegisterSpeechCommandMessage command) { if (command == null) { throw new ArgumentNullApplicationException(nameof(command)); } var title = new Title(command.Title); var urlValue = new UrlValue(command.Url); var description = new Description(command.Description); var type = new SpeechType(command.Type); var speech = new Domain.SpeechAggregate.Speech(AggregateId.NewId(), title, urlValue, description, type); await _speechRepository.CreateAsync(speech); await _domainEventSubscriber.Subscribe(speech); }
public void EqualityIsTrueWhenObjectsAreSameIdentitiesTest() { //Arrange var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url.com"); //Act var speech1 = new SpeechAggregate.Speech(title, url, description, SpeechType.Conferences); var speech2 = new SpeechAggregate.Speech(title, url, description, SpeechType.SelfPacedLabs); //Assert Assert.Equal(speech1, speech2); Assert.True(speech1.Equals(speech2)); Assert.True(speech1.Equals((object)speech2)); Assert.Equal(speech1.GetHashCode(), speech2.GetHashCode()); }
public void DeleteSpeechWhenExpectedVersionIsEqualsToAggregateVersionShouldMarkSpeechAsDeleted() { //Arrange long expectedVersion = 0; var id = Guid.NewGuid(); var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description(@"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url.com"); var speech = new SpeechAggregate.Speech(id, title, url, description, SpeechType.Conferences); //Act speech.Delete(id, expectedVersion); //Assert Assert.True(speech.IsDeleted); }
public void ChangeTitleWithValiidArgumentsShouldApplySpeechTitleChangedEvent() { //Arrange long expectedVersion = 0; string newTitle = "new Lorem Ipsum is simply dummy text of the printin"; var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description(@"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url.com"); var speech = new SpeechAggregate.Speech(title, url, description, SpeechType.Conferences); //Act speech.ChangeTitle(newTitle, expectedVersion); //Assert Assert.Equal(newTitle, speech.Title.Value); Assert.Equal(description, speech.Description); Assert.Equal(url, speech.Url); }
public void WriteValuesToListItem_WhenGivenValueAndDescription_ShouldCopyValueAndDescription() { using (ShimsContext.Create()) { // Arrange var actualFieldName = string.Empty; var expectedField = new UrlFieldInfo("InternalName", Guid.NewGuid(), null, null, null); var actualUrlValue = new SPFieldUrlValue(); var expectedUrlValue = new UrlValue() { Description = "Awesome sauce description!", Url = "http://www.gsoft.com/team" }; var fakeListItemShim = new ShimSPListItem() { ItemSetStringObject = (internalName, value) => { actualUrlValue = value as SPFieldUrlValue; actualFieldName = internalName; } }; IFieldValueWriter writer; var fakeListItem = fakeListItemShim.Instance; using (var scope = UnitTestServiceLocator.BeginLifetimeScope()) { writer = scope.Resolve <IFieldValueWriter>(); } // Act writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(expectedField, expectedUrlValue)); // Assert Assert.AreEqual(expectedUrlValue.Url, actualUrlValue.Url); Assert.AreEqual(expectedUrlValue.Description, actualUrlValue.Description); Assert.AreEqual(expectedField.InternalName, actualFieldName); } }
public void RegisterSpeechWithValidDataRaiseDomainEvent(SpeechType speechType) { //Arrange var id = Guid.NewGuid(); var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url.com"); //Act var speech = new SpeechAggregate.Speech(id, title, url, description, speechType); var domainEvent = speech.GetUncommittedEvents().SingleOrDefault(); var speechCreateEvent = (SpeechCreatedEvent)domainEvent; //Assert Assert.IsAssignableFrom <SpeechCreatedEvent>(domainEvent); Assert.NotNull(speechCreateEvent); Assert.Equal(id, speechCreateEvent.AggregateId); Assert.Equal(url, speechCreateEvent.Url); Assert.Equal(title, speechCreateEvent.Title); Assert.Equal(description, speechCreateEvent.Description); Assert.Equal(speechType, speechCreateEvent.Type); Assert.True(DateTime.UtcNow < speechCreateEvent.OcurrendOn); }
public void CreateMediaWithValidMediaFileRetunrSuccess() { //Arrange var title = new Title("Lorem Ipsum is simply dummy text of the printin"); var description = new Description("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took "); var url = new UrlValue("http://url.com"); var file = new MediaFile(Guid.NewGuid(), new UrlValue( "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE2ybMU?ver=c5fc&q=90&m=6&h=201&w=358&b=%23FFFFFFFF&l=f&o=t&aim=true")); //Act var speech = new SpeechAggregate.Speech(title, url, description, SpeechType.Conferences); speech.CreateMedia(file, 0); var domainEvent = speech.GetUncommittedEvents().SingleOrDefault(s => s is MediaFileCreatedEvent); var mediaFileCreatedEvent = (MediaFileCreatedEvent)domainEvent; //Assert Assert.Contains(file, speech.MediaFileItems); Assert.NotNull(speech.MediaFileItems.Select(f => f.File)); Assert.NotNull(mediaFileCreatedEvent); Assert.Equal(mediaFileCreatedEvent.AggregateId, speech.Id); Assert.Equal(mediaFileCreatedEvent.AggregateVersion, speech.Version); }
public MediaFileCreatedEvent(Guid id, UrlValue file, int version) { Id = id.ToString(); File = file; Version = version; }
public void ChangeUrl(UrlValue url, long originalVersion) { AddDomainEvent(new SpeechUrlChangedEvent(Id, url.Value), originalVersion); }
public MediaFile(Guid id, UrlValue file) { Id = id; File = file ?? throw new ArgumentNullAggregateException(nameof(file)); }
public MediaFileCreatedEvent(Guid aggregateId, Guid mediaFileId, UrlValue file) { MediaFileId = mediaFileId; AggregateId = aggregateId; File = file; }
public MediaFile(UrlValue file) { File = file ?? throw new ArgumentNullAggregateException(nameof(file)); }