public static Guid GetTemplateIdFromType(this Type t) { SitecoreTypeAttribute sitecoreTypeAttribute = (SitecoreTypeAttribute)t.GetCustomAttribute(typeof(SitecoreTypeAttribute), true); Guid templateId; if (Guid.TryParse(sitecoreTypeAttribute.TemplateId, out templateId)) { return(templateId); } return(Guid.Empty); }
public void Configure_ConfigurationIsIncorrectType_ExceptionThrown() { //Assign var attr = new SitecoreTypeAttribute(); var config = Substitute.For <AbstractTypeConfiguration>(); var type = typeof(StubClass); var templateIdExpected = Guid.Empty; var branchIdExptected = Guid.Empty; //Act attr.Configure(type, config); //Assert }
public void Configure_AttributeHasInvalidBranchId_ExceptionThrown() { //Assign var attr = new SitecoreTypeAttribute(); var type = typeof(StubClass); var templateIdExpected = Guid.Empty; var branchIdExptected = Guid.Empty; attr.BranchId = "not a guid"; //Act var config = attr.Configure(type) as SitecoreTypeConfiguration; //Assert }
public void Configure_ConfigurationIsOfCorrectType_NoExceptionThrown() { //Assign var attr = new SitecoreTypeAttribute(); var type = typeof(StubClass); var templateIdExpected = Guid.Empty; var branchIdExptected = Guid.Empty; //Act var config = attr.Configure(type) as SitecoreTypeConfiguration; //Assert Assert.AreEqual(type, config.Type); Assert.AreEqual(new ID(templateIdExpected), config.TemplateId); Assert.AreEqual(new ID(branchIdExptected), config.BranchId); }
public void Configure_AttributeHasBranchId_BranchIdSetOnConfig() { //Assign var attr = new SitecoreTypeAttribute(); var type = typeof(StubClass); var templateIdExpected = Guid.Empty; var branchIdExptected = new Guid(); attr.BranchId = branchIdExptected.ToString(); //Act var config = attr.Configure(type) as SitecoreTypeConfiguration; //Assert Assert.AreEqual(type, config.Type); Assert.AreEqual(new ID(templateIdExpected), config.TemplateId); Assert.AreEqual(new ID(branchIdExptected), config.BranchId); }