public void SerializeType_ArrayProperty_SerializedAsArray() { string serialized = ButlerSerializer.SerializeType <ButlerTestClass3> (); const string expected = ButlerTestClass3.ExpectedSerialized; string errorMessage = $"Expected: {expected}; Actual: {serialized}"; Assert.AreEqual(expected, serialized, errorMessage); }
public void SerializeType_JsonIgnoredProperty_PropertyIgnored() { string serialized = ButlerSerializer.SerializeType <ButlerTestClass1> (); const string expected = ButlerTestClass1.ExpectedSerialized; string errorMessage = $"Expected: {expected}; Actual: {serialized}"; Assert.AreEqual(expected, serialized, errorMessage); }
public void SerializeType_JsonConstructorAttribute_ConstructorRespected() { string serialized = ButlerSerializer.SerializeType <ButlerTestClass2> (); const string expected = ButlerTestClass2.ExpectedSerialized; string errorMessage = $"Expected: {expected}; Actual: {serialized}"; Assert.AreEqual(expected, serialized, errorMessage); }
public void SerializeType_NoButlerSerializerSettings_Serialized() { string serialized = ButlerSerializer.SerializeType <ButlerTestClass0> (); const string expected = ButlerTestClass0.ExpectedSerialized; string errorMessage = $"Expected: {expected}; Actual: {serialized}"; Assert.AreEqual(expected, serialized, errorMessage); }
public void SerializeType_NoJsonPropertyAttribute_PropertySerialized() { string serialized = ButlerSerializer.SerializeType <ButlerTestClass4> (); const string expected = ButlerTestClass4.ExpectedSerialized; string errorMessage = $"Expected: {expected}; Actual: {serialized}"; Assert.AreEqual(expected, serialized, errorMessage); }
public void SerializeType_NoJsonSerializerSettings_Serialized() { ButlerSerializerSettings serializerSettings = new ButlerSerializerSettings(Assembly.GetExecutingAssembly()); serializerSettings.PreferredAttributeTypesOnConstructor = new[] { typeof(JsonConstructorAttribute) }; string serialized = ButlerSerializer.SerializeType <ButlerTestClass0> (serializerSettings); const string expected = ButlerTestClass0.ExpectedSerialized; string errorMessage = $"Expected: {expected}; Actual: {serialized}"; Assert.AreEqual(expected, serialized, errorMessage); }
public void SerializeType_NoPreferredCtorAttributes_Serialized() { ButlerSerializerSettings serializerSettings = new ButlerSerializerSettings(Assembly.GetExecutingAssembly()); JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings(); jsonSerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; jsonSerializerSettings.Formatting = Formatting.None; serializerSettings.JsonSerializerSettings = jsonSerializerSettings; string serialized = ButlerSerializer.SerializeType <ButlerTestClass0> (serializerSettings); const string expected = ButlerTestClass0.ExpectedSerialized; string errorMessage = $"Expected: {expected}; Actual: {serialized}"; Assert.AreEqual(expected, serialized, errorMessage); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="args">Event args.</param> private void Execute(object sender, EventArgs args) { ThreadHelper.ThrowIfNotOnUIThread(); ConfirmationWindow confirmationWindow = new ConfirmationWindow(); DialogResult buildConfirmation = confirmationWindow.ShowDialogWithMessage("JsonButler needs to build solution to identify this type.\nProceed?"); if (buildConfirmation != DialogResult.OK) { return; } _package.Dte?.Solution.SolutionBuild.Build(true); TextSelection textSelection = _package.Dte?.ActiveDocument.Selection as TextSelection; CodeElement codeElement = EditorUtilities.GetCodeElement(textSelection); AlertWindow alertWindow; if (codeElement == null) { alertWindow = new AlertWindow(); alertWindow.ShowDialogWithMessage("Invalid code element selected for serialization."); return; } ITypeResolutionService resolutionService = GetResolutionService(codeElement.ProjectItem.ContainingProject); Type type = resolutionService.GetType(codeElement.FullName); ButlerSerializerSettings serializerSettings = new ButlerSerializerSettings(type?.Assembly); JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings(); SerializerContractResolver contractResolver = new SerializerContractResolver(); contractResolver.SerializationType = _package.SerializationType; jsonSerializerSettings.ContractResolver = contractResolver; jsonSerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; jsonSerializerSettings.Formatting = Formatting.Indented; serializerSettings.JsonSerializerSettings = jsonSerializerSettings; string serialized = ButlerSerializer.SerializeType(type, serializerSettings); Clipboard.SetText(serialized); _package.DoAlert("Serialized JSON contents copied to clipboard."); }