public void SaveForecasts_OneOfEachTypeOfForecastToSave_MapsAndCallsSaveOnClient() { // Arrange var fixture = InitializeFixture(); var client = fixture.Create <Mock <IServiceStackClient> >(); SaveForecastsRequest request = null; client .Setup(x => x.PostAsync(It.IsAny <SaveForecastsRequest>())) .ReturnsAsync(new SaveForecastsResponse()) .Callback <SaveForecastsRequest>(x => request = x); var appSettingsMock = new Mock <IAppSettings>(); var sut = new ForecastService(appSettingsMock.Object) { Client = () => client.Object }; var forecastMonth = fixture.Create <ForecastMonthDto>(); var forecastDtos = fixture .CreateMany <ForecastDto>() .ToList(); forecastMonth.ForecastDtos = forecastDtos; // Act sut.SaveForecasts(forecastMonth); // Assert Assert.That(request, Is.Not.Null); Assert.That(request.ForecastMonthDto, Is.EqualTo(forecastMonth)); Assert.That(request.ForecastMonthDto.ForecastDtos, Is.EqualTo(forecastDtos)); client.VerifyAll(); }
public async Task <SaveForecastsResponse> SaveForecasts(ForecastMonthDto forecastMonth) { var request = new SaveForecastsRequest { ForecastMonthDto = forecastMonth }; var result = await TrySendAsync(request, () => "An error occured while saving forecastMonth"); return(result); }
public void PostValue_SavesAsExpected() { // Arrange var fixture = InitializeFixture(); var forecastType = fixture.Create <Mock <ForecastType> >(); forecastType.SetupGet(x => x.Id).Returns(22); var forecastTypeRepoMock = FreezeMock <IForecastTypeRepository>(); forecastTypeRepoMock.Setup(x => x.GetAll()).Returns(new List <ForecastType> { forecastType.Object }); var userMock = fixture.Create <Mock <User> >(); userMock.SetupGet(x => x.EntityId).Returns(10); var userRepoMock = FreezeMock <IUserRepository>(); userRepoMock.Setup(x => x.GetByUserID(10)).Returns(userMock.Object); var forecastMonthMock = fixture.Create <Mock <ForecastMonth> >(); forecastMonthMock.CallBase = false; forecastMonthMock.SetupGet(x => x.Id).Returns(66); ForecastMonth buildtMonth = null; var monthRepoMock = FreezeMock <IForecastMonthRepository>(); monthRepoMock.Setup(x => x.GetById(0)).Returns((ForecastMonth)null); monthRepoMock.Setup(x => x.SaveOrUpdate(It.IsAny <ForecastMonth>())).Callback <ForecastMonth>(x => buildtMonth = x); var monthFactoryMock = FreezeMock <IForecastMonthFactory>(); monthFactoryMock.Setup(x => x.CreateForecastMonth(1, 2013, It.IsAny <User>(), It.IsAny <User>())).Returns(forecastMonthMock.Object); var request = new SaveForecastsRequest { ForecastMonthDto = new ForecastMonthDto { Id = 0, UserId = 10, Month = 1, Year = 2013, CreatedById = 10, ForecastDtos = new List <ForecastDto> { new ForecastDto { Date = new DateTime(2013, 1, 1), ForecastType = new ForecastTypeDto { Id = 22 }, ForecastProjectHoursDtos = new Collection <ForecastProjectHoursDto>() } } } }; var sut = fixture.Create <SaveForecastsService>(); // Act var result = sut.Post(request); // Assert monthRepoMock.VerifyAll(); monthFactoryMock.VerifyAll(); forecastType.VerifyAll(); userRepoMock.VerifyAll(); forecastMonthMock.Verify(x => x.AddForecast(new DateTime(2013, 1, 1), forecastType.Object, null)); Assert.That(result, Is.TypeOf <SaveForecastsResponse>()); Assert.That(((SaveForecastsResponse)result).ForecastMonthId, Is.EqualTo(buildtMonth.Id)); Assert.That(buildtMonth.Id, Is.EqualTo(66)); }