public void CreateEvent_WithEmptyCustomizations_SuccessfulEventCreation() { var customizationsDto = new CustomizationsDto(); var result = _eventService.CreateEvent(_creatorId, _track.Id, DateTime.Now, customizationsDto); Assert.AreEqual(_event.Id, result.Id); }
public void CreateEvent_InvalidRating_ThrowsArgumentOutOfRangeException() { var customizationsDto = new CustomizationsDto(); customizationsDto.Rating = 20; Assert.Throws <ArgumentOutOfRangeException>(() => _eventService.CreateEvent(_creatorId, _track.Id, DateTime.Now, customizationsDto)); }
public void EditEvent_UpdateEmptyCustomizations_Successful() { var customizations = new CustomizationsDto(); var result = _eventService.EditEvent(_creatorId, new EventToEditDto(_event.Id, customizations)); Assert.AreEqual(_event.Id, result.Id); Assert.AreEqual(_event.CreatedAt, result.CreatedAt); Assert.AreEqual(_event.TrackId, result.TrackId); }
public EventDto CreateEvent(Guid userId, Guid trackId, DateTime createdAt, CustomizationsDto customizationsDto) { var track = TryGetAccessToTrack(userId, trackId); CheckNotAllowedCustomizationsInDto(customizationsDto, track.AllowedCustomizations, trackId); var customizations = new Customizations(customizationsDto, track.AllowedCustomizations); var newEvent = new Event(Guid.NewGuid(), createdAt, trackId, customizations); var createdEvent = _eventRepository.TryCreate(newEvent); return(new EventDto(createdEvent)); }
public void TestCustomizations_ForEmptyCustomizationsAndFullAllowedCustomizations_Successful() { var customizationsDto = new CustomizationsDto(); var customizations = new Customizations(customizationsDto, new List <CustomizationType>()); Assert.IsNull(customizations.Comment); Assert.IsNull(customizations.Rating); Assert.IsNull(customizations.Scale); Assert.IsNull(customizations.Photo); Assert.IsNull(customizations.Geotag); }
public void EditEvent_SavedEventHasCustomizations_SuccessfulEventEditing() { var customizations = new CustomizationsDto(); customizations.Comment = "comment 2"; customizations.PhotoUrl = "photo url"; var result = _eventService.EditEvent(_creatorId, new EventToEditDto(_event.Id, customizations)); Assert.AreEqual(_event.Id, result.Id); Assert.AreEqual(_event.CreatedAt, result.CreatedAt); Assert.AreEqual(_event.TrackId, result.TrackId); }
public void Setup() { _creatorId = Guid.NewGuid(); var allowedCustomizations = new List <CustomizationType>() { CustomizationType.Comment, CustomizationType.Scale, CustomizationType.Rating }; _track = new Track( Guid.NewGuid(), "Test track", DateTime.Now, _creatorId, allowedCustomizations); var customizationsDto = new CustomizationsDto(); customizationsDto.Comment = "comment"; customizationsDto.Scale = 5; customizationsDto.PhotoUrl = "photo"; var customizationsForDto = new List <CustomizationType>(allowedCustomizations) { CustomizationType.Photo }; _event = new Event( Guid.NewGuid(), DateTime.Now, _track.Id, new Customizations(customizationsDto, customizationsForDto)); var trackRepositoryMock = new Mock <ITrackRepository>(); trackRepositoryMock.Setup(method => method.TryGetTrackById(_track.Id)) .Returns(_track); var eventRepositoryMock = new Mock <IEventRepository>(); eventRepositoryMock.Setup(method => method.TryCreate(It.IsAny <Event>())) .Returns(_event); eventRepositoryMock.Setup(method => method.TryGetById(_event.Id)) .Returns(_event); eventRepositoryMock.Setup(method => method.TryUpdate(It.IsAny <Event>())) .Returns(_event); _eventService = new EventService(eventRepositoryMock.Object, trackRepositoryMock.Object); }
private void CheckNotAllowedCustomizationsInDto( CustomizationsDto customizationsDto, IEnumerable <CustomizationType> allowedCustomizations, Guid trackId) { var givenCustomizations = Customizations.GetCustomizationTypes(customizationsDto); var notAllowedCustomizations = givenCustomizations.Where(c => !allowedCustomizations.Contains(c)).ToList(); if (notAllowedCustomizations.Any()) { throw new DomainException(DomainExceptionType.NotAllowedCustomizations, trackId, notAllowedCustomizations); } }
public void CreateEvent_NotAllowedCustomizations_ThrowsNotAllowedCustomizations() { DomainException exception = null; var customizationsDto = new CustomizationsDto(); customizationsDto.PhotoUrl = "p"; try { _eventService.CreateEvent(_creatorId, _track.Id, DateTime.Now, customizationsDto); } catch (DomainException e) { exception = e; } Assert.AreEqual(DomainExceptionType.NotAllowedCustomizations, exception.Type); }
public void TestCustomizations_ForCustomizationsAndSomeAllowedCustomizations_Successful() { var customizationsDto = new CustomizationsDto(); customizationsDto.Comment = "comment"; customizationsDto.Rating = 3; var customizations = new Customizations(customizationsDto, new List <CustomizationType>() { CustomizationType.Comment }); Assert.AreEqual(customizationsDto.Comment, customizations.Comment.Value); Assert.IsNull(customizations.Rating); Assert.IsNull(customizations.Scale); Assert.IsNull(customizations.Photo); Assert.IsNull(customizations.Geotag); }
public void EditEvent_NotAllowedCustomizations() { var customizations = new CustomizationsDto(); customizations.GeotagLatitude = 1; customizations.GeotagLongitude = 2; customizations.PhotoUrl = "photo url"; DomainException exception = null; try { _eventService.EditEvent(_creatorId, new EventToEditDto(_event.Id, customizations)); } catch (DomainException e) { exception = e; } Assert.AreEqual(DomainExceptionType.NotAllowedCustomizations, exception.Type); }
public void TestCustomizations_ForAllCustomizations_Successful() { var customizationsDto = new CustomizationsDto(); customizationsDto.Comment = "comment"; customizationsDto.Rating = 3; customizationsDto.Scale = 10; customizationsDto.PhotoUrl = "photo"; customizationsDto.GeotagLatitude = 30; customizationsDto.GeotagLongitude = 30; var customizations = new Customizations(customizationsDto, _allTypes); Assert.AreEqual(customizationsDto.Comment, customizations.Comment.Value); Assert.AreEqual(customizationsDto.Comment, customizations.Comment.Value); Assert.AreEqual(customizationsDto.Rating, customizations.Rating.Value); Assert.AreEqual(customizationsDto.Scale, customizations.Scale.Value); Assert.AreEqual(customizationsDto.PhotoUrl, customizations.Photo.Value); Assert.AreEqual(customizationsDto.GeotagLatitude, customizations.Geotag.Latitude); Assert.AreEqual(customizations.Geotag.Longitude, customizations.Geotag.Longitude); }