public void Orientation() { for (var i = 1; i <= 8; i++) { var resourceName = string.Format("Tests.Resources.orientation.Landscape_{0}.jpg", i); var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); byte[] content; using (var output = new MemoryStream()) { resource.CopyTo(output); content = output.ToArray(); } var media = new MediaBuilder(this.Session).WithContent(content).Build(); media.MediaType = new MediaTypes(this.Session).Infer(media.Content); var image = new ImageBuilder(this.Session).WithOriginal(media).Build(); this.Session.Derive(true); using (Stream stream = new MemoryStream(image.Responsive.Content)) { var responsive = new Bitmap(stream); responsive.Width.ShouldEqual(600); responsive.Height.ShouldEqual(450); } } }
public void Hash() { var binary = new byte[] { 0, 1, 2, 3 }; var octetStream = new MediaTypes(this.DatabaseSession).OctetStream; this.DatabaseSession.Commit(); var media = new MediaBuilder(this.DatabaseSession).WithContent(binary).WithMediaType(octetStream).Build(); this.DatabaseSession.Derive(true); Assert.IsTrue(media.ExistMediaContent); Assert.IsTrue(media.MediaContent.ExistHash); }
public void HashedContent() { var binary = new byte[] { 0, 1, 2, 3 }; var sameBinary = new byte[] { 0, 1, 2, 3 }; var differentBinary = new byte[] { 1, 0, 2, 3 }; var octetStream = new MediaTypes(this.DatabaseSession).OctetStream; var media1 = new MediaBuilder(this.DatabaseSession).WithContent(binary).WithMediaType(octetStream).Build(); var media2 = new MediaBuilder(this.DatabaseSession).WithContent(sameBinary).WithMediaType(octetStream).Build(); var media3 = new MediaBuilder(this.DatabaseSession).WithContent(differentBinary).WithMediaType(octetStream).Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(media1.MediaContent.Hash, media2.MediaContent.Hash); Assert.AreNotEqual(media1.MediaContent.Hash, media3.MediaContent.Hash); }
public void Image() { var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("Tests.Resources.logo.png"); byte[] content; using (var output = new MemoryStream()) { resource.CopyTo(output); content = output.ToArray(); } var media = new MediaBuilder(this.Session).WithContent(content).Build(); media.MediaType = new MediaTypes(this.Session).Infer(media.Content); var image = new ImageBuilder(this.Session).WithOriginal(media).Build(); this.Session.Derive(true); }
public void PdfWithJpegExtension() { var media = new MediaBuilder(this.DatabaseSession).Build(); var input = Assembly.GetExecutingAssembly().GetManifestResourceStream("Allors.Resources.PdfAs.jpg"); if (input != null) { using (var output = new MemoryStream()) { input.CopyTo(output); media.Content = output.ToArray(); media.MediaType = new MediaTypes(this.DatabaseSession).Infer(media.Content); } } this.DatabaseSession.Derive(true); Assert.AreEqual("application/pdf", media.MediaType.Name); }
public ActionResult Edit(Edit model, Command? command) { if (command == Command.Cancel) { return this.RedirectToRoute("Default", new { controller = "Organisation", action = "Index" }); } var organisation = (Organisation)this.AllorsSession.Instantiate(model.Id); var currentCultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture; var currentUICultureInfo = System.Threading.Thread.CurrentThread.CurrentUICulture; if (command == Command.Save) { if (this.ModelState.IsValid) { organisation.Name = model.Name; organisation.Description = model.Description; organisation.Information = model.Information; organisation.Incorporated = model.Incorporated; organisation.IncorporationDate = model.IncorporationDate.HasValue ? model.IncorporationDate.Value.ToUniversalTime() : (DateTime?)null; organisation.Owner = (Person)this.AllorsSession.Instantiate(model.Owner.Id); organisation.Employees = model.Werknemers != null ? this.AllorsSession.Instantiate(model.Werknemers.Ids) : null; if (model.Logo.PostedFile != null) { if (organisation.ExistLogo) { organisation.Logo.Delete(); } var media = new MediaBuilder(this.AllorsSession).WithContent(model.Logo.PostedFile.GetContent()).Build(); var image = new ImageBuilder(this.AllorsSession).WithOriginalFilename(model.Logo.PostedFile.FileName).WithOriginal(media).Build(); organisation.Logo = image; } if (model.Images.PostedFile != null) { var media = new MediaBuilder(this.AllorsSession).WithContent(model.Images.PostedFile.GetContent()).Build(); var image = new ImageBuilder(this.AllorsSession).WithOriginalFilename(model.Images.PostedFile.FileName).WithOriginal(media).Build(); organisation.AddImage(image); } foreach (var item in model.Images.Items) { if (item.Delete) { var image = (Image)this.AllorsSession.Instantiate(item.Id); image.Delete(); } } var derivationLog = this.AllorsSession.Derive(); if (derivationLog.HasErrors) { foreach (var error in derivationLog.Errors) { this.ModelState.AddModelError(string.Empty, error.Message); } } else { this.AllorsSession.Commit(); this.ModelState.Clear(); } } } this.Map(model, organisation); return this.View(model); }
public void OneRole() { // Arrange var media = new MediaBuilder(this.Session) .Build(); var user = new PersonBuilder(this.Session) .WithFirstName("Koen") .WithLastName("Van Exem") .WithUserName("kvex") .WithUserEmail("*****@*****.**") .WithPhoto(media) .Build(); this.Session.Derive(); this.Session.Commit(); // Bump version number user.MiddleName = "x"; this.Session.Derive(); this.Session.Commit(); var controller = new AngularController { AllorsSession = this.Session, AuthenticatedUser = user }; // Act var jsonResult = (JsonResult)controller.Main(); var response = (Response)jsonResult.Data; // Assert response.Objects.Length.ShouldEqual(2); var userObject = response.Objects.First(v => v[0].Equals(user.Id.ToString())); userObject[1].ShouldEqual(user.Strategy.ObjectVersion.ToString()); var mediaObject = response.Objects.First(v => v[0].Equals(media.Id.ToString())); mediaObject[1].ShouldEqual(media.Strategy.ObjectVersion.ToString()); response.NamedObjects.Count.ShouldEqual(1); var namedObject = response.NamedObjects["root"]; namedObject.ShouldEqual(user.Id.ToString()); }
public void ManyAndOneRole() { // Arrange var koen = new PersonBuilder(this.Session) .WithFirstName("Koen") .WithLastName("Van Exem") .WithUserName("kvex") .WithUserEmail("*****@*****.**") .Build(); var johnMedia = new MediaBuilder(this.Session) .Build(); var john = new PersonBuilder(this.Session) .WithFirstName("John") .WithLastName("Doe") .WithUserName("jod") .WithUserEmail("*****@*****.**") .WithPhoto(johnMedia) .Build(); var janeMedia = new MediaBuilder(this.Session) .Build(); var jane = new PersonBuilder(this.Session) .WithFirstName("Jane") .WithLastName("Doe") .WithUserName("jad") .WithUserEmail("*****@*****.**") .WithPhoto(janeMedia) .Build(); var organisation = new OrganisationBuilder(this.Session) .WithName("Acme") .WithOwner(koen) .WithShareholder(john) .WithShareholder(jane) .Build(); this.Session.Derive(); this.Session.Commit(); // Bump version number organisation.Description = "Acme industries"; this.Session.Derive(); this.Session.Commit(); var controller = new AngularController { AllorsSession = this.Session, AuthenticatedUser = koen }; // Act var jsonResult = (JsonResult)controller.Shareholders(); var response = (Response)jsonResult.Data; // Assert response.Objects.Length.ShouldEqual(5); var responseOrganisation = response.Objects.First(v => v[0].Equals(organisation.Id.ToString())); responseOrganisation[1].ShouldEqual(organisation.Strategy.ObjectVersion.ToString()); var responseJohn = response.Objects.First(v => v[0].Equals(john.Id.ToString())); responseJohn[1].ShouldEqual(john.Strategy.ObjectVersion.ToString()); var responseJohnMedia = response.Objects.First(v => v[0].Equals(johnMedia.Id.ToString())); responseJohnMedia[1].ShouldEqual(johnMedia.Strategy.ObjectVersion.ToString()); var responseJane = response.Objects.First(v => v[0].Equals(jane.Id.ToString())); responseJane[1].ShouldEqual(jane.Strategy.ObjectVersion.ToString()); var responseJaneMedia = response.Objects.First(v => v[0].Equals(janeMedia.Id.ToString())); responseJaneMedia[1].ShouldEqual(janeMedia.Strategy.ObjectVersion.ToString()); response.NamedObjects.Count.ShouldEqual(1); var namedObject = response.NamedObjects["root"]; namedObject.ShouldEqual(organisation.Id.ToString()); }
public void DefaultValues() { var media = new MediaBuilder(this.DatabaseSession).Build(); Assert.IsTrue(media.ExistUniqueId); }