public async Task PostReturnsBadRequestWithNullProfileIdTest() { var command = Substitute.For <IPhotoCommand>(); var sut = new PhotosController(command); using (var tokenSource = new CancellationTokenSource()) { var actual = await sut.Post(null, tokenSource.Token).ConfigureAwait(false); actual.Should().BeOfType <ErrorMessageResult>().Which.StatusCode.Should() .Be((int)HttpStatusCode.BadRequest); } }
public async Task PostCreatesNewPhotoTest() { var account = Model.Create <Account>(); var user = ClaimsIdentityFactory.BuildPrincipal(account); var photoDetails = Model.Create <PhotoDetails>(); var command = Substitute.For <IPhotoCommand>(); var model = Substitute.For <IFormFile>(); var httpContext = Substitute.For <HttpContext>(); httpContext.User = user; var routerData = new RouteData(); var actionDescriptor = new ControllerActionDescriptor(); var actionContext = new ActionContext(httpContext, routerData, actionDescriptor); var controllerContext = new ControllerContext(actionContext); using (var data = new MemoryStream()) { using (var tokenSource = new CancellationTokenSource()) { model.OpenReadStream().Returns(data); using (var sut = new PhotosController(command)) { sut.ControllerContext = controllerContext; command.CreatePhoto( Arg.Is <Photo>(x => x.ContentType == model.ContentType && x.ProfileId == account.Id && x.Data == data), tokenSource.Token) .Returns(photoDetails); var actual = await sut.Post(model, tokenSource.Token).ConfigureAwait(false); var result = actual.Should().BeOfType <CreatedAtRouteResult>().Which; result.RouteName.Should().Be("ProfilePhoto"); result.RouteValues["profileId"].Should().Be(photoDetails.ProfileId); result.RouteValues["photoId"].Should().Be(photoDetails.Id); var value = result.Value.Should().BeOfType <PhotoDetails>().Which; value.Should().BeEquivalentTo(photoDetails); } } } }
public void PhotosPost() { PhotosController photosController = new PhotosController(); Photos photos = new Photos(); photos.UserId = 2; photos.Name = "test"; photos.Width = 1; photos.Height = 1; photos.Size = 1; photos.Date = DateTime.Now; HttpResponseMessage i = photosController.Post(photos); Assert.AreEqual(i.RequestMessage, "Created."); //Assert.AreEqual(1, 1); }
public void Post_WithNewPhoto_ShouldAddPhotosDataItemToDB() { //Arrange ObjectMother.ClearDirectory(provider); //Act var result = target.Post(); //Assert Assert.AreEqual(1, fakeDataSource.Photos.FindAll().Count((item) => true)); }