Skip to content

Commit

Permalink
Upgrade to nunit4
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasweimann committed Dec 31, 2023
1 parent f5c4173 commit 620eb47
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 100 deletions.
2 changes: 1 addition & 1 deletion src/UnitTests/BotInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class BotInfoTest
public void ValidToken()
{
var botInfo = new BotInfo("123456:ABC-DEFG1234ghIkl-zyx57W2v1u123ew11");
Assert.IsNotNull(botInfo);
Assert.That(botInfo, Is.Not.Null);
Assert.That(botInfo.Id, Is.EqualTo(123456));
Assert.That(botInfo.Token, Is.EqualTo("123456:ABC-DEFG1234ghIkl-zyx57W2v1u123ew11"));
Assert.That(botInfo.BotUrl, Is.EqualTo("https://api.telegram.org/bot123456:ABC-DEFG1234ghIkl-zyx57W2v1u123ew11/"));
Expand Down
10 changes: 5 additions & 5 deletions src/UnitTests/ChatIdTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ public void TestString()
{
ChatId chatId = "test";
Assert.That(chatId.Username, Is.EqualTo("test"));
Assert.Null(chatId.Identifier);
Assert.That(chatId.Identifier, Is.Null);
}

[Test]
public void TestLongString()
{
ChatId chatId = "-10000";
Assert.That(chatId.Username, Is.EqualTo("-10000"));
Assert.Null(chatId.Identifier);
Assert.That(chatId.Identifier, Is.Null);
}

[Test]
public void TestLong()
{
ChatId chatId = -1000000000000;
Assert.That(chatId.Identifier, Is.EqualTo(-1000000000000));
Assert.Null(chatId.Username);
Assert.That(chatId.Username, Is.Null);
}

[Test]
public void TestInt()
{
ChatId chatId = -1;
Assert.That(chatId.Identifier, Is.EqualTo(-1));
Assert.Null(chatId.Username);
Assert.That(chatId.Username, Is.Null);
}

[Test]
Expand All @@ -47,7 +47,7 @@ public void TestForPrivateConstructor()
// Get the public instance constructor that takes an integer parameter.
var constructorInfoObj = myType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, CallingConventions.HasThis,
Array.Empty<Type>(), null);
Assert.IsNotNull(constructorInfoObj);
Assert.That(constructorInfoObj, Is.Not.Null);
Assert.That(constructorInfoObj.IsPrivate);
}
}
11 changes: 6 additions & 5 deletions src/UnitTests/JsonConverters/ChatBoostSourceConverterTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
Expand Down Expand Up @@ -26,8 +27,8 @@ public async Task ShouldDeserializeHttpResponse()
Assert.That(userChatBoosts, Is.Not.Null);
Assert.That(userChatBoosts.Boosts, Has.Count.EqualTo(1));
Assert.That(userChatBoosts.Boosts[0].BoostId, Is.EqualTo("abc"));
Assert.That(userChatBoosts.Boosts[0].AddDate, Is.EqualTo(123));
Assert.That(userChatBoosts.Boosts[0].ExpirationDate, Is.EqualTo(321));
Assert.That(userChatBoosts.Boosts[0].AddDate, Is.EqualTo(DateTime.Parse("1970-01-01 00:02:03")));
Assert.That(userChatBoosts.Boosts[0].ExpirationDate, Is.EqualTo(DateTime.Parse("1970-01-01 00:05:21")));
Assert.That(userChatBoosts.Boosts[0].Source.Source, Is.EqualTo(ChatBoostSourceType.Premium));
Assert.That(userChatBoosts.Boosts[0].Source, Is.TypeOf<ChatBoostSourcePremium>());
}
Expand All @@ -37,7 +38,7 @@ public void ShouldDeserializePremium()
{
const string json = "{\"boost_id\":\"abc\",\"add_date\":123,\"expiration_date\":321, \"source\": {\"source\":\"premium\", \"user\": " + User + "}}";
var deserializedJson = JsonConvert.DeserializeObject<ChatBoost>(json, JsonSerializerSettings);
Assert.NotNull(deserializedJson);
Assert.That(deserializedJson, Is.Not.Null);
Assert.That(deserializedJson.Source.Source, Is.EqualTo(ChatBoostSourceType.Premium));
Assert.That(deserializedJson.Source, Is.TypeOf<ChatBoostSourcePremium>());
}
Expand All @@ -50,7 +51,7 @@ public void ShouldDeserializeGiftCode()
User +
"}}";
var deserializedJson = JsonConvert.DeserializeObject<ChatBoost>(json, JsonSerializerSettings);
Assert.NotNull(deserializedJson);
Assert.That(deserializedJson, Is.Not.Null);
Assert.That(deserializedJson.Source.Source, Is.EqualTo(ChatBoostSourceType.GiftCode));
Assert.That(deserializedJson.Source, Is.TypeOf<ChatBoostSourceGiftCode>());
}
Expand All @@ -60,7 +61,7 @@ public void ShouldDeserializeGiveaway()
{
const string json = "{\"boost_id\":\"abc\",\"add_date\":123,\"expiration_date\":321, \"source\": {\"source\":\"giveaway\", \"giveaway_message_id\": 123}}";
var deserializedJson = JsonConvert.DeserializeObject<ChatBoost>(json, JsonSerializerSettings);
Assert.NotNull(deserializedJson);
Assert.That(deserializedJson, Is.Not.Null);
Assert.That(deserializedJson.Source.Source, Is.EqualTo(ChatBoostSourceType.Giveaway));
Assert.That(deserializedJson.Source, Is.TypeOf<ChatBoostSourceGiveaway>());
}
Expand Down
24 changes: 12 additions & 12 deletions src/UnitTests/JsonConverters/ChatIdConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,52 @@ public void ShouldDeserializeIntChatId()
{
const string json = "{ \"chat_id\":2147483647}";
var deserializedJson = JsonConvert.DeserializeObject<ForwardMessage>(json, JsonSerializerSettings);
Assert.NotNull(deserializedJson);
Assert.True(deserializedJson.ChatId.Identifier == int.MaxValue);
Assert.That(deserializedJson, Is.Not.Null);
Assert.That(deserializedJson.ChatId.Identifier == int.MaxValue, Is.True);
}

[Test]
public void ShouldDeserializeLongChatId()
{
const string json = "{ \"chat_id\":9223372036854775807}";
var deserializedJson = JsonConvert.DeserializeObject<ForwardMessage>(json, JsonSerializerSettings);
Assert.NotNull(deserializedJson);
Assert.True(deserializedJson.ChatId.Identifier == long.MaxValue);
Assert.That(deserializedJson, Is.Not.Null);
Assert.That(deserializedJson.ChatId.Identifier == long.MaxValue, Is.True);
}

[Test]
public void ShouldDeserializeStringChatId()
{
const string json = "{ \"chat_id\":\"@chatId\"}";
var deserializedJson = JsonConvert.DeserializeObject<ForwardMessage>(json, JsonSerializerSettings);
Assert.NotNull(deserializedJson);
Assert.True(deserializedJson.ChatId.Username.Equals("@chatId"));
Assert.That(deserializedJson, Is.Not.Null);
Assert.That(deserializedJson.ChatId.Username.Equals("@chatId"), Is.True);
}

[Test]
public void ShouldSerializeIntChatId()
{
ChatId chatId = int.MaxValue;
var json = JsonConvert.SerializeObject(chatId, JsonSerializerSettings);
Assert.NotNull(json);
Assert.True(json.Contains($"{int.MaxValue}"));
Assert.That(json, Is.Not.Null);
Assert.That(json.Contains($"{int.MaxValue}"), Is.True);
}

[Test]
public void ShouldSerializeLongChatId()
{
ChatId chatId = long.MaxValue;
var json = JsonConvert.SerializeObject(chatId, JsonSerializerSettings);
Assert.NotNull(json);
Assert.True(json.Contains($"{long.MaxValue}"));
Assert.That(json, Is.Not.Null);
Assert.That(json.Contains($"{long.MaxValue}"), Is.True);
}

[Test]
public void ShouldSerializeStringChatId()
{
ChatId chatId = "@chatId";
var json = JsonConvert.SerializeObject(chatId, JsonSerializerSettings);
Assert.NotNull(json);
Assert.True(json.Contains("\"@chatId\""));
Assert.That(json, Is.Not.Null);
Assert.That(json.Contains("\"@chatId\""), Is.True);
}
}
12 changes: 6 additions & 6 deletions src/UnitTests/JsonConverters/StringEnumConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public void SerializeElementType()
};

var json = JsonConvert.SerializeObject(objectToSerialize, JsonSerializerSettings);
Assert.NotNull(json);
Assert.True(json.Contains("bank_statement"));
Assert.That(json, Is.Not.Null);
Assert.That(json.Contains("bank_statement"), Is.True);
}

[Test]
Expand All @@ -32,8 +32,8 @@ public void SerializeParseMode()
};

var json = JsonConvert.SerializeObject(objectToSerialize, JsonSerializerSettings);
Assert.NotNull(json);
Assert.True(json.Contains("markdown"));
Assert.That(json, Is.Not.Null);
Assert.That(json.Contains("markdown"), Is.True);
}

[Test]
Expand All @@ -44,7 +44,7 @@ public void SerializeStickerType()
Type = StickerType.CustomEmoji
};
var json = JsonConvert.SerializeObject(sicker, JsonSerializerSettings);
Assert.NotNull(json);
Assert.True(json.Contains("custom_emoji"));
Assert.That(json, Is.Not.Null);
Assert.That(json.Contains("custom_emoji"), Is.True);
}
}
Loading

0 comments on commit 620eb47

Please sign in to comment.