public void GetAllByCalendarId_WithCorrectData_ShouldReturnCorrectResult() { var calendar = new Calendar { Id = "Test1", Title = "Default", }; var color = new Color { Id = 1, Name = "Test", Hex = "TestHex", }; var model = new Event { Id = "Test1", Title = "Test", StartDateTime = new DateTime(2020, 02, 02, 12, 0, 0), EndDateTime = new DateTime(2020, 02, 02, 12, 30, 0), Description = "test description", Location = "Hotel Test", Coordinates = "42.99, 32.99", Calendar = calendar, CalendarId = calendar.Id, Color = color, }; var eventCalendarViewModel = new EventCalendarViewModel { Id = "Test1", Title = "Test", StartDateTime = new DateTime(2020, 02, 02, 12, 0, 0), EndDateTime = new DateTime(2020, 02, 02, 12, 30, 0), CalendarId = "Test1", Description = "test description", Location = "Hotel Test", Coordinates = "42.99, 32.99", ColorHex = color.Hex, }; this.eventsRepository.Setup(x => x.All()).Returns(new List <Event> { model }.AsQueryable()); var actualResultColleciton = this.eventService.GetAllByCalendarId(calendar.Id); var expectedResult = eventCalendarViewModel; var actualResult = actualResultColleciton.First(); this.eventsRepository.Verify(x => x.All(), Times.Once); Assert.Single(actualResultColleciton); Assert.Equal(expectedResult.Title, actualResult.Title); Assert.Equal(expectedResult.StartDateTime, actualResult.StartDateTime); Assert.Equal(expectedResult.EndDateTime, actualResult.EndDateTime); }
public void GetCreateChangeViewModel_WithCorrectData_ShouldReturnCorrectly() { var user = new ApplicationUser { Id = "User1", UserName = "******", }; var color = new Color { Id = 1, Name = "Test", Hex = "TestHex", }; var calendar = new Calendar { Id = "1", Title = "Default", DefaultCalendarColorId = color.Id, DefaultCalendarColor = color, User = user, }; var eventViewModel = new EventViewModel { StartDate = DateTime.Now, StartTime = DateTime.Now, EndDate = DateTime.Now, EndTime = DateTime.Now.AddMinutes(30), ColorId = 1, }; this.calendarRepository .Setup(x => x.All()) .Returns(new List <Calendar> { calendar } .AsQueryable()); this.colorRepository.Setup(x => x.All()).Returns(new List <Color> { color }.AsQueryable()); var actualResult = this.eventService.GetCreateChangeViewModel(user.UserName); var expectedResult = eventViewModel; var actualResultOutput = actualResult.EventModel; Assert.Equal(expectedResult.Title, actualResultOutput.Title); Assert.Equal(expectedResult.CalendarId, actualResultOutput.CalendarId); Assert.Equal(expectedResult.Location, actualResultOutput.Location); Assert.Equal(expectedResult.Coordinates, actualResultOutput.Coordinates); Assert.Equal(expectedResult.Description, actualResultOutput.Description); Assert.Equal(expectedResult.StartDateTime, actualResultOutput.StartDateTime); Assert.Equal(expectedResult.EndDateTime, actualResultOutput.EndDateTime); Assert.Equal(expectedResult.ColorId, actualResultOutput.ColorId); }
public void GetDetailsViewModelById_WithCorrectData_ShouldReturnCorrectResult() { var color = new Color { Id = 1, Name = "Test", Hex = "TestHex", }; var calendar = new Calendar { Id = "1", Title = "Default", DefaultCalendarColorId = color.Id, DefaultCalendarColor = color, UserId = "UserId", }; var model = new Event { Id = "Test1", Title = "Test", StartDateTime = new DateTime(2020, 02, 02, 12, 0, 0), EndDateTime = new DateTime(2020, 02, 02, 12, 30, 0), CalendarId = calendar.Id, Calendar = calendar, Description = "test description", Location = "Hotel Test", Coordinates = "42.99, 32.99", ColorId = color.Id, Color = color, }; var eventViewModel = new EventDetailsViewModel { Id = "Test1", Title = "Test", StartDateTime = new DateTime(2020, 02, 02, 12, 0, 0), EndDateTime = new DateTime(2020, 02, 02, 12, 30, 0), CalendarTitle = "Default", Description = "test description", Location = "Hotel Test", ColorHex = color.Hex, CalendarId = calendar.Id, }; this.eventsRepository.Setup(x => x.AllAsNoTracking()).Returns(new List <Event> { model }.AsQueryable()); var actualResult = this.eventService.GetDetailsViewModelById(model.Id); var expectedResult = eventViewModel; this.eventsRepository.Verify(x => x.AllAsNoTracking(), Times.Once); Assert.Equal(expectedResult.Id, actualResult.Id); Assert.Equal(expectedResult.Title, actualResult.Title); Assert.Equal(expectedResult.CalendarTitle, actualResult.CalendarTitle); Assert.Equal(expectedResult.Location, actualResult.Location); Assert.Equal(expectedResult.Description, actualResult.Description); Assert.Equal(expectedResult.StartDateTime, actualResult.StartDateTime); Assert.Equal(expectedResult.EndDateTime, actualResult.EndDateTime); Assert.Equal(expectedResult.ColorHex, actualResult.ColorHex); }
public void GetEditChangeViewModelById_WithCorrectData_ShouldReturnCorrectResult() { var user = new ApplicationUser { Id = "User1", UserName = "******", }; var color = new Color { Id = 1, Name = "Test", Hex = "TestHex", }; var calendar = new Calendar { Id = "1", Title = "Default", DefaultCalendarColorId = color.Id, DefaultCalendarColor = color, User = user, }; var model = new Event { Id = "Test1", Title = "Test", StartDateTime = new DateTime(2020, 02, 02, 12, 0, 0), EndDateTime = new DateTime(2020, 02, 02, 12, 30, 0), CalendarId = calendar.Id, Calendar = calendar, Description = "test description", Location = "Hotel Test", Coordinates = "42.99, 32.99", ColorId = 1, }; var eventViewModel = new EventViewModel { Title = "Test", StartDate = new DateTime(2020, 02, 02, 0, 0, 0), StartTime = new DateTime(0001, 1, 1, 12, 0, 0), EndDate = new DateTime(2020, 02, 02, 0, 0, 0), EndTime = new DateTime(0001, 1, 1, 12, 30, 0), CalendarId = "1", Description = "test description", Location = "Hotel Test", Coordinates = "42.99, 32.99", ColorId = 1, }; this.calendarRepository .Setup(x => x.All()) .Returns(new List <Calendar> { calendar } .AsQueryable()); this.colorRepository.Setup(x => x.All()).Returns(new List <Color> { color }.AsQueryable()); this.eventsRepository.Setup(x => x.All()).Returns(new List <Event> { model }.AsQueryable()); var actualResult = this.eventService.GetEditChangeViewModelById(model.Id, user.UserName); var expectedResult = eventViewModel; var actualResultOutput = actualResult.EventModel; this.eventsRepository.Verify(x => x.All(), Times.Once); Assert.Equal(expectedResult.Title, actualResultOutput.Title); Assert.Equal(expectedResult.CalendarId, actualResultOutput.CalendarId); Assert.Equal(expectedResult.Location, actualResultOutput.Location); Assert.Equal(expectedResult.Coordinates, actualResultOutput.Coordinates); Assert.Equal(expectedResult.Description, actualResultOutput.Description); Assert.Equal(expectedResult.StartDateTime, actualResultOutput.StartDateTime); Assert.Equal(expectedResult.EndDateTime, actualResultOutput.EndDateTime); Assert.Equal(expectedResult.ColorId, actualResultOutput.ColorId); }