public void DeleteMaterial_UnauthorizedException_Test() { var expectedmaterial = new Material() { MaterialId = 1, SessionId = 1 }; int organizerId = 10; ISessionRepository sessionRepository = new StubISessionRepository() { GetOrganizerIdInt32 = (sessionId) => { return organizerId; } }; IMaterialRepository materialRepository = new StubIMaterialRepository() { GetInt32 = materialId => { return expectedmaterial; } }; using (ShimsContext.Create()) { MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken(); myeventToken.RegisteredUserIdGet = () => { return 100000; }; ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; }; var target = new MaterialsController(materialRepository, sessionRepository); target.Delete(expectedmaterial.MaterialId); } }
public void DeleteMaterial_Deleted_NotFail_Test() { bool called = false; var expectedmaterial = new Material() { MaterialId = 1, SessionId = 1 }; int organizerId = 10; ISessionRepository sessionRepository = new StubISessionRepository(); IMaterialRepository materialRepository = new StubIMaterialRepository() { DeleteInt32 = materialId => { Assert.AreEqual(expectedmaterial.MaterialId, materialId); called = true; }, GetOrganizerIdInt32 = materialId => { return organizerId; } }; using (ShimsContext.Create()) { MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken(); myeventToken.RegisteredUserIdGet = () => { return organizerId; }; ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; }; var target = new MaterialsController(materialRepository, sessionRepository); target.Delete(expectedmaterial.MaterialId); Assert.IsTrue(called); } }
/// <summary> /// <see cref="MyEvents.Data.IMaterialRepository"/> /// </summary> /// <param name="material"><see cref="MyEvents.Data.IMaterialRepository"/></param> /// <returns><see cref="MyEvents.Data.IMaterialRepository"/></returns> public int Add(Material material) { using (var context = new MyEventsContext()) { context.Materials.Add(material); context.SaveChanges(); return material.MaterialId; } }
public void AddMaterial_Added_NotFail_Test() { var context = new MyEventsContext(); int sessionId = context.Sessions.FirstOrDefault().SessionId; int expected = context.Materials.Count() + 1; IMaterialRepository target = new MaterialRepository(); Material material = new Material(); material.SessionId = sessionId; material.Name = Guid.NewGuid().ToString(); material.ContentType = "image/jpeg"; System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); material.Content = encoding.GetBytes("content"); target.Add(material); int actual = context.Materials.Count(); Assert.AreEqual(expected, actual); }
private List<Material> GetMaterials() { var materials = new List<Material>(); var material = new Material(); material.Name = "Presentation"; material.ContentType = "image/jpeg"; material.Content = CommonInitializer.LoadFile("FakeImages\\visualstudio.png"); materials.Add(material); return materials; }
public ActionResult UploadMaterial(MyEventsIdentity identity, int sessionId) { if (Request.Files != null && Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; var fileBytes = new byte[file.ContentLength]; file.InputStream.Read(fileBytes, 0, (int)file.ContentLength); if (fileBytes.Length != 0) { _authorizationService.ValidateSessionAuthorization(identity, sessionId); var material = new Material { SessionId = sessionId, Name = HttpUtility.HtmlDecode(file.FileName), ContentType = file.ContentType, Content = fileBytes }; _materialRepository.Add(material); return PartialView("MaterialRow", material); } } return null; }
public int Post(Material material) { if (material == null) throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); ValidateSessionAuthorization(material.SessionId); return _materialRepository.Add(material); }
public void GetMaterials_NotFail_Test() { bool called = false; var expected = new Material() { MaterialId = 10 }; ISessionRepository sessionRepository = new StubISessionRepository(); IMaterialRepository materialRepository = new StubIMaterialRepository() { GetInt32 = materialId => { Assert.AreEqual(expected.MaterialId, materialId); called = true; return expected; } }; var target = new MaterialsController(materialRepository, sessionRepository); Material actual = target.Get(expected.MaterialId); Assert.IsTrue(called); }