public async void CreateRoomAsync_Returns_New_StudioRoomDto() { var name = "StudioName"; var friendlyUrl = "FriendlyUrl"; var postalCode = "12345"; var ownerUserId = Guid.NewGuid(); var model = Studio.Create(name, friendlyUrl, postalCode, ownerUserId, _studioValidator.Object); _studioRepository .Setup(r => r.GetAsync(It.IsAny <Guid>())) .Returns(Task.FromResult(model)); var roomName = "RoomName"; var roomModel = Room.Create(model.Id, roomName); _studioRepository .Setup(r => r.CreateRoomAsync(It.IsAny <Guid>(), It.IsAny <string>())) .Returns(Task.FromResult(roomModel)); var dto = new RoomDto { StudioId = model.Id, Name = roomName }; var result = await _studioService.CreateRoomAsync(ownerUserId, model.Id, dto); Assert.NotNull(result); Assert.Equal(model.Id, result.StudioId); Assert.Equal(roomName, result.Name); }
public void CreateRoom_Returns_New_StudioRoom_With_StudioId() { var studio = Studio.Create("StudioName", "StudioFriendlyUrl", "12345", Guid.NewGuid(), _studioValidator.Object); var room = studio.CreateRoom("RoomName"); Assert.NotNull(room); Assert.Equal(studio.Id, room.StudioId); Assert.Equal("RoomName", room.Name); }
public async void ValidateAsync_Returns_Success_When_Existing_Url_Belongs_To_Same_StudioId() { var studio = Studio.Create("StudioName", "FriendlyUrl", "12345", Guid.NewGuid(), _studioValidator); _studioRepository .Setup(r => r.GetByUrlAsync(It.IsAny <string>())) .Returns(Task.FromResult(studio)); await _studioValidator.ValidateAsync(studio.Id, "StudioName", "NewUrl", "12345"); }
public void Create_Throws_UriFormatException() { _studioValidator .Setup(v => v.ValidateAsync(It.IsAny <Guid?>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ThrowsAsync(new UriFormatException()); var ex = Assert.Throws <UriFormatException>(() => Studio.Create("StudioName", "%", "12345", Guid.NewGuid(), _studioValidator.Object)); Assert.NotNull(ex); }
public void Create_Returns_New_Studio() { var ownerUserId = Guid.NewGuid(); var studio = Studio.Create("StudioName", "StudioFriendlyUrl", "12345", ownerUserId, _studioValidator.Object); Assert.NotNull(studio); Assert.Equal("StudioName", studio.Name); Assert.Equal("StudioFriendlyUrl", studio.FriendlyUrl); Assert.Equal("12345", studio.PostalCode); Assert.Equal(ownerUserId, studio.OwnerUserId); }
public async Task <StudioDto> CreateAsync(StudioDto model) { var newEntity = Studio.Create( model.Name, model.FriendlyUrl, model.PostalCode, model.OwnerUserId, _studioUrlValidator); var entity = await _studioRepository.CreateAsync(newEntity); var result = _mapper.Map <StudioDto>(entity); return(result); }
public async void ValidateAsync_Throws_StudioUrlInUseException_When_New_Studio() { var studio = Studio.Create("StudioName", "FriendlyUrl", "12345", Guid.NewGuid(), _studioValidator); _studioRepository .Setup(r => r.GetByUrlAsync(It.IsAny <string>())) .Returns(Task.FromResult(studio)); var ex = await Assert.ThrowsAsync <DomainValidationException>( () => _studioValidator.ValidateAsync(null, "StudioName", "FriendlyUrl", "12345")); Assert.NotNull(ex); Assert.NotNull(ex.InnerException); Assert.IsType <StudioUrlInUseException>(ex.InnerException); }
public async void SearchAsync_Returns_Studio_When_In_Distance() { var name = "StudioName"; var friendlyUrl = "FriendlyUrl"; var postalCode = "12345"; var outOfRangePostalCode = "54321"; var ownerUserId = Guid.NewGuid(); var distance = 10; var postalCodesInDistance = new List <PostalCodeDistance> { PostalCodeDistance.Create(postalCode, distance) }.AsEnumerable(); var searchModel = new StudioSearchModel { PostalCodeSearchCriteria = new PostalCodeSearchCriteria(postalCode, distance) }; var studios = new List <Studio> { Studio.Create(name, friendlyUrl, postalCode, ownerUserId, _studioValidator.Object), Studio.Create(name, friendlyUrl, outOfRangePostalCode, ownerUserId, _studioValidator.Object) }; _studioRepository .Setup(r => r.GetAsync(It.IsAny <Expression <Func <Studio, bool> > >())) .Returns(Task.FromResult(studios)); _postalCodeRepository .Setup(r => r.GetPostalCodesWithinDistance(It.IsAny <string>(), It.IsAny <decimal>())) .Returns(Task.FromResult(postalCodesInDistance)); var result = await _studioService.SearchAsync(searchModel); Assert.NotNull(result); Assert.Equal(1, result.Count); Assert.Equal(studios.First().Id, result.First().Id); Assert.Equal(distance, result.First().Distance); }
public async void CreateAsync_Returns_New_StudioDto() { var name = "StudioName"; var friendlyUrl = "FriendlyUrl"; var postalCode = "12345"; var ownerUserId = Guid.NewGuid(); var model = Studio.Create(name, friendlyUrl, postalCode, ownerUserId, _studioValidator.Object); _studioRepository .Setup(r => r.CreateAsync(It.IsAny <Studio>())) .Returns(Task.FromResult(model)); var dto = new StudioDto { Name = name, FriendlyUrl = friendlyUrl, PostalCode = postalCode, OwnerUserId = ownerUserId }; var result = await _studioService.CreateAsync(dto); Assert.NotNull(result); Assert.Equal(name, result.Name); Assert.Equal(friendlyUrl, result.FriendlyUrl); Assert.Equal(ownerUserId, result.OwnerUserId); Assert.Equal(postalCode, result.PostalCode); }