public void ShouldPreventCreateWithType() { var appointment = new Appointment() { Title = "test", Type = "", Crew = "Test" }; var sqlMock = new Mock <ISqlOrm>(); var repo = new AppointmentRepository(sqlMock.Object); var ex = Assert.ThrowsAsync <InvalidEntityException>(() => repo.CreateAsync(appointment)).Result; Assert.Equal("type", ex.PropertyName); }
public void ShouldPreventOverlappingAppointments() { var appointment = new Appointment() { Title = "test", Type = "type", Crew = "test", UserId = 23, Start = DateTime.UtcNow, End = DateTime.UtcNow.AddDays(1) }; var sqlMock = new Mock <ISqlOrm>(); sqlMock.Setup(m => m.QueryAsync <Appointment>(It.IsAny <string>(), It.Is <object>(o => JsonConvert.SerializeObject(o) == JsonConvert.SerializeObject(new { userId = appointment.UserId, start = appointment.Start, end = appointment.End, crew = appointment.Crew, id = 0 })))).ReturnsAsync(new Appointment()); var repo = new AppointmentRepository(sqlMock.Object); var ex = Assert.ThrowsAsync <OverlappingAppointmentException>(() => repo.CreateAsync(appointment)).Result; }
public void ShouldCreateAppointment() { var appointment = new Appointment() { Title = "test", Type = "type", Crew = "test", UserId = 23, Start = DateTime.UtcNow, End = DateTime.UtcNow.AddDays(1) }; var sqlMock = new Mock <ISqlOrm>(); sqlMock.Setup(m => m.QueryAsync <Appointment>(It.IsAny <string>(), It.Is <object>(o => JsonConvert.SerializeObject(o) == JsonConvert.SerializeObject(new { userId = appointment.UserId, start = appointment.Start, end = appointment.End, crew = appointment.Crew, id = 0 })))).ReturnsAsync((Appointment)null); sqlMock.Setup(m => m.CreateEntityAsync(It.IsAny <string>(), appointment)).ReturnsAsync(1).Verifiable(); var repo = new AppointmentRepository(sqlMock.Object); var result = repo.CreateAsync(appointment).Result; sqlMock.Verify(m => m.CreateEntityAsync(It.IsAny <string>(), appointment), Times.Once); Assert.Equal(1, result); }