Skip to content

Commit

Permalink
add test sample and removed some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlm committed May 8, 2024
1 parent 756f311 commit 3d19ff0
Show file tree
Hide file tree
Showing 330 changed files with 33,951 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static RenderFragment ToMarkupRenderFragment(this string? markup)
/// <returns>raw string content</returns>
public static string GetStringContent(this RenderFragment renderFragment)
{
#pragma warning disable BL0006 // Do not use RenderTree types
var builder = new RenderTreeBuilder();
var stringBuilder = new StringBuilder();
renderFragment(builder);
Expand All @@ -55,6 +56,7 @@ public static string GetStringContent(this RenderFragment renderFragment)
break;
}
}
#pragma warning restore BL0006 // Do not use RenderTree types
return stringBuilder.ToString();
}
}
2 changes: 1 addition & 1 deletion source/libraries/Crazor.Blazor/Components/BoolProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public BoolProperty(bool b)
public static bool operator ==(BoolProperty? lhs, BoolProperty? rhs) => lhs?._value == rhs?._value;
public static bool operator !=(BoolProperty? lhs, BoolProperty? rhs) => lhs?._value != rhs?._value;

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (obj is BoolProperty bp)
return _value == bp._value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public QueryParameterAttribute(string name, string description, string title)
/// <summary>
/// Initial value for the parameter
/// </summary>
public string Value { get; set; }
public string? Value { get; set; }

}
}
26 changes: 18 additions & 8 deletions source/libraries/Crazor/CardApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ public virtual async Task<AdaptiveCard> RenderCardAsync(bool isPreview, Cancella
Context.ServiceOptions.Logger.Response?.Invoke(this.Activity, outboundCard);
}

#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
System.Diagnostics.Debug.WriteLine("===outbound card===");
System.Diagnostics.Debug.WriteLine(outboundCard.ToJson());
}
#endif

return outboundCard;
}

Expand Down Expand Up @@ -970,10 +978,11 @@ private async Task AddMetadataToCard(AdaptiveCard outboundCard, bool isPreview,
data[Constants.IDDATA_KEY] = action.Id;

// hide goofy feedback panel
if (Activity.ChannelId == Channels.Msteams)
{
action.AdditionalProperties["msTeams"] = new JObject() { { "feedback", new JObject() { { "hide", true } } } };
}
// THIS IS DISABLED UNTIL BUG IS FIXED
//if (Activity.ChannelId == Channels.Msteams)
//{
// action.AdditionalProperties["msTeams"] = new JObject() { { "feedback", new JObject() { { "hide", true } } } };
//}
}

foreach (var action in outboundCard.GetElements<AdaptiveSubmitAction>())
Expand Down Expand Up @@ -1004,10 +1013,11 @@ private async Task AddMetadataToCard(AdaptiveCard outboundCard, bool isPreview,
data[Constants.IDDATA_KEY] = action.Id;

// hide goofy feedback panel
if (Activity.ChannelId == Channels.Msteams)
{
action.AdditionalProperties["msTeams"] = new JObject() { { "feedback", new JObject() { { "hide", true } } } };
}
// THIS IS DISABLED UNTIL BUG IS FIXED
//if (Activity.ChannelId == Channels.Msteams)
//{
// action.AdditionalProperties["msTeams"] = new JObject() { { "feedback", new JObject() { { "hide", true } } } };
//}
}

foreach (var choiceSet in outboundCard.GetElements<AdaptiveChoiceSetInput>())
Expand Down
18 changes: 15 additions & 3 deletions source/libraries/Crazor/CardViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,22 @@ public static void Validate(this ICardView cardView)
{
validationResults = new List<ValidationResult>();
var value = property.GetValue(cardView);
if (!validator.TryValidateObjectRecursive(value, validationResults))
if (value == null)
{
cardView.IsModelValid = false;
cardView.AddValidationResults($"{property.Name}.", validationResults);
// if this is required and null then we have an issue.
if (property.GetCustomAttribute<RequiredAttribute>() != null)
{
cardView.IsModelValid = false;
cardView.AddValidationResults($"{property.Name}.", validationResults);
}
}
else
{
if (!validator.TryValidateObjectRecursive(value, validationResults))
{
cardView.IsModelValid = false;
cardView.AddValidationResults($"{property.Name}.", validationResults);
}
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions source/libraries/Crazor/QueryString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public string Name
internal QueryStringParameter(string name, string value = null)
{
if (name == null)
throw new ArgumentNullException("name");
throw new ArgumentNullException(nameof(name));

Name = name;
Value = value;
Expand All @@ -84,7 +84,9 @@ internal enum QueryStringSeparator
/// <summary>
/// A portable string serializer/deserializer for .NET.
/// </summary>
#pragma warning disable CA1067 // Override Object.Equals(object) when implementing IEquatable<T>
internal class QueryString : IEnumerable<QueryStringParameter>, IEquatable<QueryString>
#pragma warning restore CA1067 // Override Object.Equals(object) when implementing IEquatable<T>
{
private Dictionary<string, List<string>> _dictionary = new Dictionary<string, List<string>>();

Expand All @@ -106,7 +108,7 @@ public string this[string name]
get
{
if (name == null)
throw new ArgumentNullException("name");
throw new ArgumentNullException(nameof(name));

string value;

Expand Down Expand Up @@ -149,7 +151,7 @@ public bool TryGetValue(string name, out string value)
public bool TryGetValues(string name, out string[] values)
{
if (name == null)
throw new ArgumentNullException("name");
throw new ArgumentNullException(nameof(name));

List<string> storedValues;

Expand Down Expand Up @@ -179,7 +181,7 @@ public int Count()
public void Add(string name, string value = null)
{
if (name == null)
throw new ArgumentNullException("name");
throw new ArgumentNullException(nameof(name));

List<string> values;

Expand All @@ -200,7 +202,7 @@ public void Add(string name, string value = null)
public void Set(string name, string value = null)
{
if (name == null)
throw new ArgumentNullException("name");
throw new ArgumentNullException(nameof(name));

_dictionary[name] = new List<string>()
{
Expand All @@ -216,7 +218,7 @@ public void Set(string name, string value = null)
public bool Contains(string name)
{
if (name == null)
throw new ArgumentNullException("name");
throw new ArgumentNullException(nameof(name));

return _dictionary.ContainsKey(name);
}
Expand All @@ -230,7 +232,7 @@ public bool Contains(string name)
public bool Contains(string name, string value)
{
if (name == null)
throw new ArgumentNullException("name");
throw new ArgumentNullException(nameof(name));

List<string> values;

Expand Down
2 changes: 1 addition & 1 deletion source/libraries/Crazor/RouteResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void AddCardViewType(Type cardViewType)

CardRoute cardRoute;
List<RouteTemplate> list;
if (cardViewType.Name.Contains("_"))
if (cardViewType.Name.Contains('_'))
{
cardRoute = CardRoute.Parse(cardViewType.Name.Replace("_", "/"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"CrazorBlazorDemo": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "https://a24d-50-35-67-190.ngrok-free.app/",
"launchUrl": "https://24cc-50-35-67-190.ngrok-free.app",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
},
"BotName": "CrazorBlazor-Dev",
"HostUri": "https://a24d-50-35-67-190.ngrok-free.app/",
"HostUri": "https://24cc-50-35-67-190.ngrok-free.app/",
"MicrosoftAppType": "MultiTenant",
"MicrosoftAppId": "aed1e47e-fb55-407d-956d-5baaa8c74c95",
"TeamsAppId": "aed1e47e-fb55-407d-956d-5baaa8c74c95",
Expand Down
94 changes: 94 additions & 0 deletions source/samples/SharedCards/Cards/Tests/Default.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
@using Microsoft.Extensions.Hosting
@using Newtonsoft.Json
@using SharedCards.Cards.NugetSearch
@using Microsoft.Bot.Schema.Teams
@inherits CardView<CardApp>

<Card Version="1.4">
<ColumnSet Spacing="AdaptiveSpacing.None" Style="AdaptiveContainerStyle.Emphasis" Bleed="true">
<Column Width="AdaptiveWidth.Stretch">
<InputChoiceSet Binding="Index" Label="" Style="AdaptiveChoiceInputStyle.Filtered" Placeholder="Choose card">
<DataQuery Dataset="Files" />
</InputChoiceSet>
</Column>
<Column Width="AdaptiveWidth.Auto">
<ActionSet>
<ActionExecute Verb="@nameof(OnShowCard)" AssociatedInputs="@AdaptiveAssociatedInputs.Auto" Title="Show Card" />
</ActionSet>
</Column>
</ColumnSet>
</Card>


@code
{
public string? Index { get; set; }

[TempMemory]
public AdaptiveCard? TestCard { get; set; } = null;

public void OnShowCard()
{
// get file card
if (Index != null)
{
var index = int.Parse(Index);
var choice = GetFileChoices(null, index, 1)[0];
string root = Path.GetDirectoryName(this.GetType().Assembly.Location);
var path = Path.Combine(root, "Cards", "Tests", choice.Title);
var json = System.IO.File.ReadAllText(path);
TestCard = JsonConvert.DeserializeObject<AdaptiveCard>(json);
}
}

public async override Task<AdaptiveCard> RenderCardAsync(bool isPreview, CancellationToken cancellationToken)
{
var card = await base.RenderCardAsync(isPreview, cancellationToken);

if (TestCard != null)
{
// merge
foreach (var element in TestCard.Body)
card.Body.Add(element);

foreach (var action in TestCard.Actions)
card.Actions.Add(action);
}

return card;
}

public override async Task<AdaptiveChoice[]> OnSearchChoicesAsync(SearchInvoke search, CancellationToken cancellationToken)
{
await Task.CompletedTask;

if (search.Dataset == "Files")
{
return GetFileChoices(search.QueryText, search.QueryOptions.Skip, search.QueryOptions.Top);
}
return Array.Empty<AdaptiveChoice>();
}

private AdaptiveChoice[] GetFileChoices(string query, int skip, int top)
{
//get the full location of the assembly with DaoTests in it
string root = Path.GetDirectoryName(this.GetType().Assembly.Location);
int i = 0;
var folder = Path.Combine(root, App.Route.Route.TrimStart('/').Replace('/', Path.DirectorySeparatorChar));
return Directory.EnumerateFiles(folder, "*.json", SearchOption.AllDirectories)
.Select(p =>
{
var title = Path.GetRelativePath(root, p).Substring("Cards\\Tests\\".Length);
return new AdaptiveChoice()
{
Title = title,
Value = i++.ToString()
};
})
.Where(choice => choice.Title.Contains(query?.Trim() ?? String.Empty, StringComparison.OrdinalIgnoreCase))
.Skip(skip)
.Take(top)
.ToArray();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "This card's action will open a URL"
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Action.OpenUrl",
"url": "https://adaptivecards.io"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "This card's action will show another card"
}
],
"actions": [
{
"type": "Action.ShowCard",
"title": "No Style",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "This card has no style"
}
]
}
},
{
"type": "Action.ShowCard",
"title": "Default Style",
"card": {
"type": "AdaptiveCard",
"style": "default",
"body": [
{
"type": "TextBlock",
"text": "This card has default style"
}
]
}
},
{
"type": "Action.ShowCard",
"title": "Emphasis Style",
"card": {
"type": "AdaptiveCard",
"style": "emphasis",
"body": [
{
"type": "TextBlock",
"text": "This card has emphasis style"
}
]
}
}
]
}
Loading

0 comments on commit 3d19ff0

Please sign in to comment.