public async Task TestPostSocialMediaAsync() { var model = new OrganizationSocialMediaPresenceBindingModel(); var response = await controller.PostSocialMediaAsync(1, model); socialMediaHandler.Verify(x => x.HandleSocialMediaPresenceAsync <Organization>(It.IsAny <SocialMediaBindingModelBase <Organization> >(), It.IsAny <ApiController>()), Times.Once()); }
public async Task TestHandleSocialMediaPresenceAsync_ModelIsInvalid() { controller.ModelState.AddModelError("key", "error"); var model = new OrganizationSocialMediaPresenceBindingModel(); var response = await handler.HandleSocialMediaPresenceAsync <Organization>(model, controller); Assert.IsInstanceOfType(response, typeof(InvalidModelStateResult)); }
public async Task TestHandleSocialMediaPresenceAsync() { userProvider.Setup(x => x.GetCurrentUser()).Returns(new DebugWebApiUser()); userProvider.Setup(x => x.GetBusinessUser(It.IsAny <IWebApiUser>())).Returns(new Business.Service.User(1)); socialMediaService.Setup(x => x.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(new SocialMediaDTO()); socialMediaService.Setup(x => x.CreateAsync(It.IsAny <SocialMediaPresence <Organization> >())).ReturnsAsync(new SocialMedia()); var model = new OrganizationSocialMediaPresenceBindingModel(); model.SocialMediaTypeId = SocialMediaType.Facebook.Id; var response = await handler.HandleSocialMediaPresenceAsync <Organization>(model, controller); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <SocialMediaDTO>)); userProvider.Verify(x => x.GetCurrentUser(), Times.Once()); userProvider.Verify(x => x.GetBusinessUser(It.IsAny <IWebApiUser>()), Times.Once()); socialMediaService.Verify(x => x.CreateAsync(It.IsAny <SocialMediaPresence <Organization> >()), Times.Once()); socialMediaService.Verify(x => x.SaveChangesAsync(), Times.Once()); socialMediaService.Verify(x => x.GetByIdAsync(It.IsAny <int>()), Times.Once()); }
public void TestToSocialMediaPresence() { var userId = 2; var user = new User(userId); var id = 1; var value = "value"; var socialMediaTypeId = SocialMediaType.Facebook.Id; var model = new OrganizationSocialMediaPresenceBindingModel { SocialableId = id, SocialMediaTypeId = socialMediaTypeId, Value = value }; var instance = model.ToSocialMediaPresence(user); Assert.IsInstanceOfType(instance, typeof(OrganizationSocialMediaPresence)); var socialMediaPresence = (OrganizationSocialMediaPresence)instance; Assert.AreEqual(id, socialMediaPresence.OrganizationId); Assert.AreEqual(socialMediaTypeId, socialMediaPresence.SocialMediaTypeId); Assert.AreEqual(value, socialMediaPresence.Value); Assert.IsTrue(Object.ReferenceEquals(user, socialMediaPresence.Create.User)); }
public Task <IHttpActionResult> PostSocialMediaAsync(int organizationId, [FromBody] OrganizationSocialMediaPresenceBindingModel model) { return(socialMediaHandler.HandleSocialMediaPresenceAsync <Organization>(model, this)); }