public async Task CanCreateEventAliasAsync() { _configuration.DeleteIndexes(_client); _configuration.ConfigureIndexes(_client); var indexes = await _client.GetIndicesPointingToAliasAsync(_eventIndex.Name); Assert.Equal(0, indexes.Count); var alias = await _client.GetAliasAsync(descriptor => descriptor.Alias(_eventIndex.Name)); Assert.False(alias.IsValid); Assert.Equal(0, alias.Indices.Count); await _eventRepository.AddAsync(new PersistentEvent { Message = "Test", Type = Event.KnownTypes.Log, Date = DateTimeOffset.Now, OrganizationId = TestConstants.OrganizationId, ProjectId = TestConstants.ProjectId, StackId = TestConstants.StackId }); await _client.RefreshAsync(); alias = await _client.GetAliasAsync(descriptor => descriptor.Alias(_eventIndex.Name)); Assert.True(alias.IsValid); Assert.Equal(1, alias.Indices.Count); indexes = await _client.GetIndicesPointingToAliasAsync(_eventIndex.Name); Assert.Equal(1, indexes.Count); await _eventRepository.AddAsync(new PersistentEvent { Message = "Test", Type = Event.KnownTypes.Log, Date = DateTimeOffset.Now.SubtractMonths(1), OrganizationId = TestConstants.OrganizationId, ProjectId = TestConstants.ProjectId, StackId = TestConstants.StackId }); await _client.RefreshAsync(); indexes = await _client.GetIndicesPointingToAliasAsync(_eventIndex.Name); Assert.Equal(2, indexes.Count); }
public async void Can_Add_Event() { // Arrange var testEvent = new NetCoreReact.Data.Entities.Event { Id = Guid.NewGuid(), Title = "Test title", Description = "Test description", StartDate = DateTime.Now, EndDate = DateTime.Now.AddHours(1), AllDay = false, Place = "Skype" }; // Act using (var context = new EventsAppDbContext(_contextOptions)) { var repository = new EventRepository(context); var evnt = await repository.AddAsync(testEvent); } // Assert using (var context = new EventsAppDbContext(_contextOptions)) { var evnt = await context.Events.FindAsync(testEvent.Id); Assert.Equal(testEvent.Id, evnt.Id); Assert.Equal(testEvent.Title, evnt.Title); Assert.Equal(testEvent.Description, evnt.Description); Assert.Equal(testEvent.StartDate, evnt.StartDate); Assert.Equal(testEvent.EndDate, evnt.EndDate); Assert.Equal(testEvent.AllDay, evnt.AllDay); Assert.Equal(testEvent.Place, evnt.Place); } }
public async Task CanCreateEventAliasAsync() { _configuration.DeleteIndexes(_client); _configuration.ConfigureIndexes(_client); await _client.RefreshAsync(); var indexes = await _client.GetIndicesPointingToAliasAsync(_eventIndex.AliasName); Assert.Equal(0, indexes.Count); var alias = await _client.GetAliasAsync(descriptor => descriptor.Alias(_eventIndex.AliasName)); Assert.False(alias.IsValid); Assert.Equal(0, alias.Indices.Count); var ev = await _eventRepository.AddAsync(new PersistentEvent { Message = "Test", Type = Event.KnownTypes.Log, Date = DateTimeOffset.Now.StartOfMonth().AddDays(1), OrganizationId = TestConstants.OrganizationId, ProjectId = TestConstants.ProjectId, StackId = TestConstants.StackId }); Assert.NotNull(ev?.Id); Assert.True(ObjectId.Parse(ev.Id).CreationTime.IntersectsMinute(DateTime.UtcNow)); await _client.RefreshAsync(); alias = await _client.GetAliasAsync(descriptor => descriptor.Alias(_eventIndex.AliasName)); Assert.True(alias.IsValid); Assert.Equal(1, alias.Indices.Count); indexes = await _client.GetIndicesPointingToAliasAsync(_eventIndex.AliasName); Assert.Equal(1, indexes.Count); var date = DateTimeOffset.UtcNow.StartOfMonth().SubtractSeconds(1).ToLocalTime(); ev = await _eventRepository.AddAsync(new PersistentEvent { Message = "Test", Type = Event.KnownTypes.Log, Date = date, OrganizationId = TestConstants.OrganizationId, ProjectId = TestConstants.ProjectId, StackId = TestConstants.StackId }); Assert.NotNull(ev?.Id); Assert.Equal(date, ObjectId.Parse(ev.Id).CreationTime); await _client.RefreshAsync(); indexes = await _client.GetIndicesPointingToAliasAsync(_eventIndex.AliasName); Assert.Equal(2, indexes.Count); }
public async Task <ActionResult <IEnumerable <EventDayDto> > > CreateEvent(EventDayDto dto) { if (await repo.GetEventAsync(dto.Name, false) != null) { ModelState.AddModelError("Name", "Name in use"); return(BadRequest(ModelState)); } var eventday = mapper.Map <Models.Entities.EventDay>(dto); await repo.AddAsync(eventday); if (await repo.SaveAsync()) { var model = mapper.Map <EventDayDto>(eventday); return(CreatedAtAction(nameof(GetEvent), new { name = model.Name }, model)); } else { return(BadRequest()); } }
//ToDo Validate speakerId public async Task <ActionResult <LectureDto> > AddLecture(string name, LectureDto model) { var eventId = (await repo.GetEventAsync(name, false))?.Id; if (eventId is null) { return(NotFound()); } var lecture = mapper.Map <Lecture>(model); lecture.EventDayId = (int)eventId; await repo.AddAsync(lecture); if (await repo.SaveAsync()) { return(CreatedAtAction("Get", new { id = lecture.Id, name }, mapper.Map <LectureDto>(lecture))); } else { return(StatusCode(500)); } }
public void Post([FromBody] Event value) { value.CreatedTime = DateTime.UtcNow; eventRepository.AddAsync(value); }