public void ThenCatchesJsonSerializationExceptionAndReturnFalse() { IJsonDeserializeAdaptor adaptorStub = new JsonDeserializeAdaptorThrowExceptionStub(new Exception()); IValidCardData validCardData = new ValidCardData(adaptorStub, new StartingStatsDummy()); Assert.False(validCardData.Execute("Not Json").Valid); Assert.True(validCardData.Execute("Not Json").ErrorMessage.Trim().ToLower() .Contains("failed to parse json")); Assert.IsNull(validCardData.Execute("This is real json").ValidCardData); }
public void ThenReturnsFalse(string weight1, string weight2, string weight3) { Dictionary <string, IStartingStat> stats = new Dictionary <string, IStartingStat> { { "Money", new StartingStatStub(5, 10, 0) }, { "Health", new StartingStatStub(5, 10, 0) }, { "Power", new StartingStatStub(5, 10, 0) } }; Dictionary <string, float> weights = new Dictionary <string, float>() { { weight1, 0.75f }, { weight2, 0.5f }, { weight3, 0.1f } }; ICardOption cardOptionOne = new CardOptionsStub( "Option One", "Option One Description", new PlayerStatsToChangeStub(new Dictionary <string, int> { { "Money", -2 }, { "Power", 2 }, { "Health", -2 } }), new string[0]); ICardOption cardOptionTwo = new CardOptionsStub( "Option Two", "Option Two Description", new PlayerStatsToChangeStub(new Dictionary <string, int> { { "Money", 2 }, { "Power", 0 - 2 }, { "Health", 2 } }), new string[0]); IStartingStats startingStats = new StartingStatsStub(stats, weights, 2); ICard card = new CardStub(Guid.NewGuid().ToString(), "Card Title", "Card Description", "http://google.com/hello.png", new[] { cardOptionOne, cardOptionTwo }, "Common"); IJsonDeserializeAdaptor adaptorStub = new JsonDeserializeAdaptorStub(card); IValidCardData validCardData = new ValidCardData(adaptorStub, startingStats); Assert.False(validCardData.Execute("This is real json").Valid); Assert.True(validCardData.Execute("This is real json").ErrorMessage.ToLower().Trim() .Contains("invalid weight value")); Assert.True(validCardData.Execute("This is real json").ErrorMessage.ToLower().Trim() .Contains(card.CardID.ToLower())); Assert.IsNull(validCardData.Execute("This is real json").ValidCardData); }
public void ThenReturnsTrue(int optionsCount, int valueCount) { string[] values = GetRanomValues(valueCount); ICardOption[] cardOptions = CreateCardOptions(optionsCount, values); Dictionary <string, IStartingStat> stats = GetStatsWithValues(values); Dictionary <string, float> weights = new Dictionary <string, float>() { { "Common", 0.75f }, { "Rare", 0.5f }, { "Epic", 0.1f } }; IStartingStats startingStats = new StartingStatsStub(stats, weights, optionsCount); ICard card = new CardStub("Card ID", "Card Title", "Card Description", "http://google.com/hello.png", cardOptions, "Common"); IJsonDeserializeAdaptor adaptorStub = new JsonDeserializeAdaptorStub(card); IValidCardData validCardData = new ValidCardData(adaptorStub, startingStats); Assert.True(validCardData.Execute("This is real json").Valid); Assert.True(validCardData.Execute("This is real json").ValidCardData == card); }