public void _01_Pathfinder_Solves_The_Puzzle() { SlidingPuzzleMap map = new SlidingPuzzleMap( "111111;" + "100011;" + "110001;" + "100001;" + "100011;" + "11W111;" + "111111"); SlidingPuzzleState startingState = new SlidingPuzzleState(new Vector2Int(1, 2)); var processor = new SlidingPuzzleProcessor(map); var pathfinder = new Pathfinder.PuzzlePathfinder <Vector2Int, SlidingPuzzleState>().RecalculateGrah(processor, startingState, new Vector2Int[] { _up, _down, _left, _right }); Assert.That(pathfinder.Graph.Count, Is.EqualTo(10), $"Incorect graph size"); Assert.That(pathfinder.StatesToGraphMap.Count, Is.EqualTo(10), $"Incorect graph map size"); Assert.That(pathfinder.StatesToGraphMap, Contains.Key(startingState)); var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); var path = pathfinder.GetClosestWinPath(startingState); stopwatch.Stop(); Debug.Log($"Pathfinding had taken: {stopwatch.ElapsedMilliseconds} ms [{stopwatch.ElapsedTicks} ticks]"); Assert.That(path.Succesfull, Is.EqualTo(true), $"Path is not marked as succesful"); Assert.That(path.Path, Is.EqualTo(new Vector2Int[] { _up, _right, _up, _left, _down }), $"Path is incorrect"); }
public void TestNumberReader() { var reader = ColumnReaders.NumberReader("foo"); var m = new ParsedMetrics(new LabelDict("env")); reader(m, "1"); Assert.That(m.Metrics, Has.Exactly(1).Items); Assert.That(m.Metrics, Contains.Key("foo")); Assert.That(m.Metrics, Contains.Value(1.0)); Assert.That(m.Labels.Count, Is.EqualTo(0)); reader(m, "2.0"); Assert.That(m.Metrics, Has.Exactly(1).Items); Assert.That(m.Metrics, Contains.Key("foo")); Assert.That(m.Metrics, Contains.Value(2.0)); Assert.That(m.Labels.Count, Is.EqualTo(0)); reader(m, "2.0e1"); Assert.That(m.Metrics, Has.Exactly(1).Items); Assert.That(m.Metrics, Contains.Key("foo")); Assert.That(m.Metrics, Contains.Value(20.0)); Assert.That(m.Labels.Count, Is.EqualTo(0)); Assert.That(() => reader(m, ""), Throws.TypeOf <ParserError>()); Assert.That(() => reader(m, "nope"), Throws.TypeOf <ParserError>()); }
public void ApiException_Converts_To_ValidationProblemDetails_AllowedRegex() { try { var _ = _factory.Api <PortfoliosApi>().GetPortfolio("@£$@£%", "@@@@@@"); } catch (ApiException e) { Assert.That(e.IsValidationProblem, Is.True, "Response should indicate that there was a validation error with the request"); // An ApiException.ErrorContent thrown because of a request validation contains a JSON serialized LusidValidationProblemDetails if (e.TryGetValidationProblemDetails(out var errorResponse)) { //Should identify that there was a validation error with the code Assert.That(errorResponse.Errors, Contains.Key("code")); Assert.That(errorResponse.Errors["code"].Single(), Is.EqualTo("Values for the field code must be comprised of either alphanumeric characters, hyphens or underscores. For more information please consult the documentation.")); //Should identify that there was a validation error with the scope Assert.That(errorResponse.Errors, Contains.Key("scope")); Assert.That(errorResponse.Errors["scope"].Single(), Is.EqualTo("Values for the field scope must be comprised of either alphanumeric characters, hyphens or underscores. For more information please consult the documentation.")); Assert.That(errorResponse.Detail, Does.Match("One or more elements of the request were invalid.*")); Assert.That(errorResponse.Name, Is.EqualTo("InvalidRequestFailure")); } else { Assert.Fail("The request should have failed due to a validation error, and the validation details should be returned"); } } }
public void ImmunityHasCorrectData(string creature) { Assert.That(table, Contains.Key(creature)); var datas = table[creature] .Select(helper.ParseEntry) .Where(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == FeatConstants.SpecialQualities.Immunity); var testCaseSpecialQualityDatas = GetTestCaseData(creature); foreach (var data in datas) { Assert.That(testCaseSpecialQualityDatas.Any(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == FeatConstants.SpecialQualities.Immunity && d[DataIndexConstants.SpecialQualityData.FocusIndex] == data[DataIndexConstants.SpecialQualityData.FocusIndex] ), Is.True, $"TEST CASE: No Immunity to {data[DataIndexConstants.SpecialQualityData.FocusIndex]} in test case"); var testCaseData = testCaseSpecialQualityDatas.First(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == FeatConstants.SpecialQualities.Immunity && d[DataIndexConstants.SpecialQualityData.FocusIndex] == data[DataIndexConstants.SpecialQualityData.FocusIndex]); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FrequencyQuantityIndex], Is.EqualTo(0.ToString()), "TEST CASE: Frequency Quantity"); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FrequencyTimePeriodIndex], Is.Empty, "TEST CASE: Frequency Time Period"); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FocusIndex], Is.Not.Empty, "TEST CASE: Focus"); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.PowerIndex], Is.EqualTo(0.ToString()), "TEST CASE: Power"); Assert.That(data[DataIndexConstants.SpecialQualityData.FrequencyQuantityIndex], Is.EqualTo(0.ToString()), "XML: Frequency Quantity"); Assert.That(data[DataIndexConstants.SpecialQualityData.FrequencyTimePeriodIndex], Is.Empty, "XML: Frequency Time Period"); Assert.That(data[DataIndexConstants.SpecialQualityData.FocusIndex], Is.Not.Empty, "XML: Focus"); Assert.That(data[DataIndexConstants.SpecialQualityData.PowerIndex], Is.EqualTo(0.ToString()), "XML: Power"); } }
public void PsionicHasCorrectData(string creature) { Assert.That(table, Contains.Key(creature)); var datas = table[creature] .Select(helper.ParseEntry) .Where(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == FeatConstants.SpecialQualities.Psionic); var testCaseSpecialQualityDatas = GetTestCaseData(creature); foreach (var data in datas) { Assert.That(testCaseSpecialQualityDatas.Any(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == FeatConstants.SpecialQualities.Psionic && d[DataIndexConstants.SpecialQualityData.FocusIndex] == data[DataIndexConstants.SpecialQualityData.FocusIndex]), Is.True, $"TEST CASE: Psionic - {data[DataIndexConstants.SpecialQualityData.FocusIndex]}"); var testCaseData = testCaseSpecialQualityDatas.First(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == FeatConstants.SpecialQualities.Psionic && d[DataIndexConstants.SpecialQualityData.FocusIndex] == data[DataIndexConstants.SpecialQualityData.FocusIndex]); var focus = testCaseData[DataIndexConstants.SpecialQualityData.FocusIndex]; Assert.That(focus, Is.Not.Empty, "TEST CASE: Focus"); Assert.That(Convert.ToInt32(testCaseData[DataIndexConstants.SpecialQualityData.FrequencyQuantityIndex]), Is.Not.Negative, $"TEST CASE: {focus} - Frequency Quantity"); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FrequencyTimePeriodIndex], Is.Not.Empty, focus, $"TEST CASE: {focus} - Frequency Time Period"); Assert.That(Convert.ToInt32(testCaseData[DataIndexConstants.SpecialQualityData.PowerIndex]), Is.Zero, focus, $"TEST CASE: {focus} - Power"); focus = data[DataIndexConstants.SpecialQualityData.FocusIndex]; Assert.That(focus, Is.Not.Empty, "XML: Focus"); Assert.That(Convert.ToInt32(data[DataIndexConstants.SpecialQualityData.FrequencyQuantityIndex]), Is.Not.Negative, $"XML: {focus} - Frequency Quantity"); Assert.That(data[DataIndexConstants.SpecialQualityData.FrequencyTimePeriodIndex], Is.Not.Empty, focus, $"XML: {focus} - Frequency Time Period"); Assert.That(Convert.ToInt32(data[DataIndexConstants.SpecialQualityData.PowerIndex]), Is.Zero, focus, $"XML: {focus} - Power"); } }
public async Task CanPassHeadersAlongWithRequest() { var receivedHeaders = new ConcurrentQueue <KeyValuePair <string, string> >(); _activator.Handle <SomeRequest>(async(bus, context, request) => { foreach (var kvp in context.Headers) { receivedHeaders.Enqueue(kvp); } await bus.Reply(new SomeReply()); }); var theBus = _busStarter.Start(); const string customHeaderKey = "x-custom-header"; const string customHeaderValue = "it works!"; var optionalHeaders = new Dictionary <string, string> { { customHeaderKey, customHeaderValue } }; await theBus.SendRequest <SomeReply>(new SomeRequest(), optionalHeaders); var dictionary = receivedHeaders.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); Assert.That(dictionary, Contains.Key(customHeaderKey)); Assert.That(dictionary[customHeaderKey], Is.EqualTo(customHeaderValue), $"Did not find key-value-pair {customHeaderKey}={customHeaderValue} among the received headers"); }
public void RegenerationHasCorrectFrequency(string creature) { Assert.That(table, Contains.Key(creature)); var collection = table[creature]; var testCaseSpecialQualityDatas = GetTestCaseData(creature); foreach (var entry in collection) { var data = helper.ParseEntry(entry); if (data[DataIndexConstants.SpecialQualityData.FeatNameIndex] != FeatConstants.SpecialQualities.Regeneration) { continue; } var testCaseData = testCaseSpecialQualityDatas.First(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == FeatConstants.SpecialQualities.Regeneration); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FrequencyQuantityIndex], Is.EqualTo(1.ToString()), "TEST CASE: Frequency Quantity"); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FrequencyTimePeriodIndex], Is.EqualTo(FeatConstants.Frequencies.Round), "TEST CASE: Frequency Time Period"); Assert.That(data[DataIndexConstants.SpecialQualityData.FrequencyQuantityIndex], Is.EqualTo(1.ToString()), "XML: Frequency Quantity"); Assert.That(data[DataIndexConstants.SpecialQualityData.FrequencyTimePeriodIndex], Is.EqualTo(FeatConstants.Frequencies.Round), "XML: Frequency Time Period"); } }
public async Task Auth_EnableDisableValidated() { string name = _uniqueKeys.GetKey("TST"); AuthMethod am = new AuthMethod(name, EnumAuthMethods.AppRole); string path = am.Path; Debug.WriteLine("EnDisValid: Enabling first"); Assert.True(await _vaultSystemBackend.AuthEnable(am)); // Now get listing of methods and search for our test one. Debug.WriteLine("EnDisValid: Getting List."); Dictionary <string, AuthMethod> authMethods = await _vaultSystemBackend.AuthListAll(); Assert.NotNull(authMethods); Assert.That(authMethods, Contains.Key(path)); // Now disable and verify it is not in list. Debug.WriteLine("EnDisValid: Disabling..."); Assert.True(await _vaultSystemBackend.AuthDisable(am)); Debug.WriteLine("EnDisValid: Get new list LatestMethods..."); Dictionary <string, AuthMethod> latestMethods = await _vaultSystemBackend.AuthListAll(); Debug.WriteLine("EnDisValid: Final Asserts"); Assert.NotNull(latestMethods); Assert.That(latestMethods, !Contains.Key(path)); }
public void CreatureWithSpellsAttack_HasMagicSpells(string creature) { Assert.That(table, Contains.Key(creature)); foreach (var entry in table[creature]) { var valid = helper.ValidateEntry(entry); Assert.That(valid, Is.True, $"Invalid entry: {entry}"); } var hasSpellsAttack = table[creature] .Select(helper.ParseEntry) .Any(d => d[DataIndexConstants.AttackData.NameIndex] == "Spells"); var caster = collectionSelector.SelectFrom(TableNameConstants.TypeAndAmount.Casters, creature); if (hasSpellsAttack) { Assert.That(caster, Is.Not.Empty); } else { Assert.That(caster, Is.Empty); } }
public void TestParsing() { ConfigParser.YamlConfig config = ConfigParser.Parse(@" match: - executableName: foo.exe executablePathRegex: .*test.* profiler: foo: 1 uploader: versionAssembly: Bla "); Assert.That(config, Is.Not.Null, "config not null"); Assert.That(config.Match, Has.Count.EqualTo(1), "section count"); Assert.Multiple(() => { Assert.That(config.Match[0].ExecutableName, Is.EqualTo("foo.exe"), "section 0 executable name"); Assert.That(config.Match[0].ExecutablePathRegex, Is.EqualTo(".*test.*"), "section 0 executable regex"); Assert.That(config.Match[0].Profiler, Has.Count.EqualTo(1), "section 0 profiler option count"); Assert.That(config.Match[0].Profiler, Contains.Key("foo"), "section 0 profiler option 'foo'"); Assert.That(config.Match[0].Profiler["foo"], Is.EqualTo("1"), "section 0 profiler option 'foo' value"); Assert.That(config.Match[0].Uploader, Is.Not.Null, "section 0 uploader options"); Assert.That(config.Match[0].Uploader.VersionAssembly, Is.EqualTo("Bla"), "section 0 version assembly"); }); }
private void AssertLennaImg(KTXTextureImporter tex) { Assert.That(tex.Identifier, Is.EqualTo(new byte[] { (byte)'«', (byte)'K', (byte)'T', (byte)'X', (byte)' ', (byte)'1', (byte)'1', (byte)'»', (byte)'\r', (byte)'\n', (byte)'\x1A', (byte)'\n' })); Assert.That(tex.Endianess, Is.EqualTo(0x04030201)); Assert.That(tex.GlType, Is.Zero); Assert.That(tex.GlTypeSize, Is.EqualTo(1)); Assert.That((UInt32)tex.GlFormat, Is.Zero); Assert.That(tex.GlInternalFormat, Is.EqualTo(KTXPixelFormat.COMPRESSED_RGB8_ETC2)); Assert.That(tex.GlBaseInternalFormat, Is.EqualTo(KTXPixelFormat.RGB)); Assert.That(tex.Width, Is.EqualTo(512)); Assert.That(tex.Height, Is.EqualTo(512)); Assert.That(tex.Depth, Is.EqualTo(0)); Assert.That(tex.NumArrayElements, Is.EqualTo(0)); Assert.That(tex.NumFaces, Is.EqualTo(1)); Assert.That(tex.MipMapCount, Is.EqualTo(10)); Assert.That(tex.KeyValuePairs, Is.Not.Null); Assert.That(tex.KeyValuePairs.Count, Is.EqualTo(1)); Assert.That(tex.KeyValuePairs, Contains.Key("KTXOrientation")); Assert.That(tex.KeyValuePairs["KTXOrientation"], Is.EqualTo("S=r,T=d,R=i")); Assert.That(tex.DataOffset, Is.EqualTo(96)); }
public void GetMetadata_ReturnsMetadata() { var commandAttribute = new CommandAttribute( "CommandGroup", "CommandName", typeof(Resources), "TestResource"); var commandAttributeExplicit = (IMetadataProvider)commandAttribute; var metadata = commandAttributeExplicit.GetMetadata(typeof(CommandStub)); Assert.That(metadata, Is.Not.Null); Assert.That(metadata, Contains.Item(new KeyValuePair <string, object>( nameof(CommandAttribute.Group), "CommandGroup"))); Assert.That(metadata, Contains.Item(new KeyValuePair <string, object>( nameof(CommandAttribute.Name), "CommandName"))); Assert.That(metadata, Contains.Item(new KeyValuePair <string, object>( nameof(CommandAttribute.HelpText), "This is a test resource."))); Assert.That(metadata, Contains.Key(nameof(CommandMetadata.ParametersMetadata))); var parametersMetadata = (IList <CommandParameterMetadata>)metadata[ nameof(CommandMetadata.ParametersMetadata)]; Assert.That(parametersMetadata, Is.Not.Null); Assert.That(parametersMetadata, Has.Length.EqualTo(1)); var parameterMetadata = parametersMetadata[0]; Assert.That(parameterMetadata, Is.Not.Null); Assert.That(parameterMetadata.Index, Is.EqualTo(0)); Assert.That(parameterMetadata.Name, Is.EqualTo("valid")); Assert.That(parameterMetadata.HelpText, Is.EqualTo("This is a test resource.")); }
public void Output_Intrinsics_ThreadId() { const string ThreadIDKey = "ThreadID"; var testThreadIDValue = _random.Next(0, int.MaxValue); // Arrange var testEnricher = new TestEnricher(); var threadIdEnricher = new TestEnricher() .WithUserPropValue(ThreadIDKey, testThreadIDValue); var formatter = new NewRelicFormatter() .WithPropertyMapping(ThreadIDKey, NewRelicLoggingProperty.ThreadId); var testOutputSink = new TestSinkWithFormatter(formatter); var testLogger = TestHelpers.GetLogger(testOutputSink, testEnricher, threadIdEnricher); // Act testLogger.Warning(LogMessage); // Assert Asserts.NoSerilogErrorsCountOutputs(_testRunDebugLogs, testOutputSink.InputsAndOutputs, LogMessage); var resultDic = TestHelpers.SerializeOutputJSON(testOutputSink.InputsAndOutputs[0]); //additional 1 for threadid Asserts.PropertyCountsMatch(testEnricher, countIntrinsicProperties + 1, resultDic); Assert.That(resultDic, Contains.Key("thread.id")); Assert.That(testOutputSink.InputsAndOutputs[0].LogEvent.Properties[ThreadIDKey].ToString(), Is.EqualTo(resultDic["thread.id"].GetString())); }
public void TestNested() { TimerStack myTimer = TimerStack.Instance; myTimer.Reset(); using (myTimer.Scoped("foo")) { for (int i = 0; i < 5; i++) { using (myTimer.Scoped("bar")) { } } } var rootChildren = myTimer.RootNode.Children; Assert.That(rootChildren, Contains.Key("foo")); Assert.AreEqual(rootChildren["foo"].NumCalls, 1); var fooChildren = rootChildren["foo"].Children; Assert.That(fooChildren, Contains.Key("bar")); Assert.AreEqual(fooChildren["bar"].NumCalls, 5); myTimer.Reset(); Assert.AreEqual(myTimer.RootNode.Children, null); }
public void When_Populates_Allowed_Dictionary_With_Single_Value() { var device = Device.Create <Dummy>(); Assert.That(device.Allowed, Contains.Key("start")); Assert.That(device.Allowed["start"], Has.Member("stop")); }
public void CreatureWithUnnaturalAttack_HasNoDamageForEquipmentAttacks(string creature) { Assert.That(table, Contains.Key(creature)); foreach (var entry in table[creature]) { var valid = helper.ValidateEntry(entry); Assert.That(valid, Is.True, $"Invalid entry: {entry}"); } var unnaturalAttacks = table[creature] .Select(helper.ParseEntry) .Where(d => !Convert.ToBoolean(d[DataIndexConstants.AttackData.IsNaturalIndex])); if (!unnaturalAttacks.Any()) { Assert.Pass($"{creature} has all-natural, 100% USDA Organic attacks"); } foreach (var attack in unnaturalAttacks) { if (attack[DataIndexConstants.AttackData.NameIndex] != AttributeConstants.Melee && attack[DataIndexConstants.AttackData.NameIndex] != AttributeConstants.Ranged) { continue; } Assert.That(attack[DataIndexConstants.AttackData.DamageDataIndex], Is.Empty, attack[DataIndexConstants.AttackData.NameIndex]); } }
public void TestLightPrototype([Values("wallLight", "wallLightChild")] string id) { var prototype = manager.Index <EntityPrototype>(id); Assert.Multiple(() => { Assert.That(prototype.Name, Is.EqualTo("Wall Light")); Assert.That(prototype.ID, Is.EqualTo(id)); Assert.That(prototype.Components, Contains.Key("Transform")); Assert.That(prototype.Components, Contains.Key("Velocity")); Assert.That(prototype.Components, Contains.Key("Direction")); Assert.That(prototype.Components, Contains.Key("Clickable")); Assert.That(prototype.Components, Contains.Key("Sprite")); Assert.That(prototype.Components, Contains.Key("BasicInteractable")); Assert.That(prototype.Components, Contains.Key("BasicMover")); Assert.That(prototype.Components, Contains.Key("WallMounted")); Assert.That(prototype.Components, Contains.Key("Light")); }); var componentData = prototype.Components["Light"]; var expected = new Dictionary <string, YamlNode>(); expected["startState"] = new YamlScalarNode("Off"); Assert.That(componentData, Is.EquivalentTo(expected)); }
public void CreatureWithUnnaturalAttack_HasNaturalAttack(string creature) { Assert.That(table, Contains.Key(creature)); foreach (var entry in table[creature]) { var valid = helper.ValidateEntry(entry); Assert.That(valid, Is.True, $"Invalid entry: {entry}"); } var hasUnnaturalAttack = table[creature] .Select(helper.ParseEntry) .Any(d => !Convert.ToBoolean(d[DataIndexConstants.AttackData.IsNaturalIndex])); if (!hasUnnaturalAttack) { Assert.Pass($"{creature} has all-natural, 100% USDA Organic attacks"); } var naturalAttack = table[creature] .Select(helper.ParseEntry) .FirstOrDefault(d => d[DataIndexConstants.AttackData.IsNaturalIndex] == bool.TrueString && d[DataIndexConstants.AttackData.IsSpecialIndex] == bool.FalseString); Assert.That(naturalAttack, Is.Not.Null); Assert.That(naturalAttack[DataIndexConstants.AttackData.NameIndex], Is.Not.Empty); Assert.That(naturalAttack[DataIndexConstants.AttackData.IsNaturalIndex], Is.EqualTo(bool.TrueString), naturalAttack[DataIndexConstants.AttackData.NameIndex]); Assert.That(naturalAttack[DataIndexConstants.AttackData.IsSpecialIndex], Is.EqualTo(bool.FalseString), naturalAttack[DataIndexConstants.AttackData.NameIndex]); Assert.That(naturalAttack[DataIndexConstants.AttackData.DamageDataIndex], Is.Not.Empty, naturalAttack[DataIndexConstants.AttackData.NameIndex]); }
public void BonusFeatsHaveCorrectData(string creature) { Assert.That(table, Contains.Key(creature)); var feats = featsSelector.SelectFeats(); var datas = table[creature] .Select(helper.ParseEntry) .Where(d => feats.Any(f => f.Feat == d[DataIndexConstants.SpecialQualityData.FeatNameIndex])); var testCaseSpecialQualityDatas = GetTestCaseData(creature); foreach (var data in datas) { var matchingFeat = feats.First(f => f.Feat == data[DataIndexConstants.SpecialQualityData.FeatNameIndex]); Assert.That(testCaseSpecialQualityDatas.Any(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == matchingFeat.Feat), Is.True, $"TEST CASE: {matchingFeat.Feat}"); var testCaseData = testCaseSpecialQualityDatas.First(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == matchingFeat.Feat); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FrequencyQuantityIndex], Is.EqualTo(matchingFeat.Frequency.Quantity.ToString()), $"TEST CASE: {matchingFeat.Feat} - Frequency Quantity"); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FrequencyTimePeriodIndex], Is.EqualTo(matchingFeat.Frequency.TimePeriod), $"TEST CASE: {matchingFeat.Feat} - Frequency Time Period"); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.PowerIndex], Is.EqualTo(matchingFeat.Power.ToString()), $"TEST CASE: {matchingFeat.Feat} - Power"); Assert.That(data[DataIndexConstants.SpecialQualityData.FrequencyQuantityIndex], Is.EqualTo(matchingFeat.Frequency.Quantity.ToString()), $"XML: {matchingFeat.Feat} - Frequency Quantit"); Assert.That(data[DataIndexConstants.SpecialQualityData.FrequencyTimePeriodIndex], Is.EqualTo(matchingFeat.Frequency.TimePeriod), $"XML: {matchingFeat.Feat} - Frequency Time Period"); Assert.That(data[DataIndexConstants.SpecialQualityData.PowerIndex], Is.EqualTo(matchingFeat.Power.ToString()), $"XML: {matchingFeat.Feat} - Power"); } }
public async Task AddNewRepositoryWithoutValue_GetValueFromUserAndSaveRepositoryInConfiguration() { var exampleRepo = "thirdExampleRepoUrl"; var exampleJob = "thirdExampleJob"; var parameter = "repository"; var args = new string[] { Command, parameter }; var configuration = GetDefaultConfiguration(); var userConsole = new Mock <IUserConsole>(); userConsole.Setup(c => c.ReadInput(repoName, false)).Returns(exampleRepo); userConsole.Setup(c => c.ReadInput(jenkinsJob, false)).Returns(exampleJob); var command = new SetConfiguration(GetConfigurationSerializerMock(configuration).Object, GetEncryptorMock().Object, userConsole.Object); var app = new CommandLineApplication(); app.Command(command.Name, command.Command); var code = await app.ExecuteAsync(args); Assert.That(code, Is.EqualTo(JenoCodes.Ok)); Assert.That(configuration.Repository, Contains.Key(exampleRepo)); Assert.That(configuration.Repository, Contains.Value(exampleJob)); Assert.That(configuration.Repository[exampleRepo], Is.EqualTo(exampleJob)); userConsole.Verify(c => c.ReadInput(repoName, false), Times.Once); userConsole.Verify(c => c.ReadInput(jenkinsJob, false), Times.Once); }
public void DamageReductionHasCorrectData(string creature) { Assert.That(table, Contains.Key(creature)); var datas = table[creature] .Select(helper.ParseEntry) .Where(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == FeatConstants.SpecialQualities.DamageReduction); var testCaseSpecialQualityDatas = GetTestCaseData(creature); foreach (var data in datas) { Assert.That(testCaseSpecialQualityDatas.Any(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == FeatConstants.SpecialQualities.DamageReduction), Is.True, $"TEST CASE: No Damage Reduction in test case"); var testCaseData = testCaseSpecialQualityDatas.First(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == FeatConstants.SpecialQualities.DamageReduction); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FrequencyQuantityIndex], Is.EqualTo(1.ToString()), "TEST CASE: Frequency Quantity"); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FrequencyTimePeriodIndex], Is.EqualTo(FeatConstants.Frequencies.Hit), "TEST CASE: Frequency Time Period"); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FocusIndex], Is.Not.Empty, "TEST CASE: Focus"); Assert.That(Convert.ToInt32(testCaseData[DataIndexConstants.SpecialQualityData.PowerIndex]), Is.Positive, "TEST CASE: Power"); Assert.That(data[DataIndexConstants.SpecialQualityData.FrequencyQuantityIndex], Is.EqualTo(1.ToString()), "XML: Frequency Quantity"); Assert.That(data[DataIndexConstants.SpecialQualityData.FrequencyTimePeriodIndex], Is.EqualTo(FeatConstants.Frequencies.Hit), "XML: Frequency Time Period"); Assert.That(data[DataIndexConstants.SpecialQualityData.FocusIndex], Is.Not.Empty, "XML: Focus"); Assert.That(Convert.ToInt32(data[DataIndexConstants.SpecialQualityData.PowerIndex]), Is.Positive, "XML: Power"); } }
public async Task EditSavedRepository_ReplaceOldValue() { var exampleRepo = "firstExampleRepoUrl"; var exampleJob = "newExampleJob"; var parameter = "repository"; var value = $"{exampleRepo}={exampleJob}"; var args = new string[] { Command, $"{parameter}:{value}" }; var configuration = GetDefaultConfiguration(); var userConsole = new Mock <IUserConsole>(); userConsole.Setup(c => c.ReadInput(repoName, false)).Returns(exampleRepo); userConsole.Setup(c => c.ReadInput(jenkinsJob, false)).Returns(exampleJob); var command = new SetConfiguration(GetConfigurationSerializerMock(configuration).Object, GetEncryptorMock().Object, userConsole.Object); var app = new CommandLineApplication(); app.Command(command.Name, command.Command); var code = await app.ExecuteAsync(args); Assert.That(code, Is.EqualTo(JenoCodes.Ok)); Assert.That(configuration.Repository, Contains.Key(exampleRepo)); Assert.That(configuration.Repository, Contains.Value(exampleJob)); Assert.That(configuration.Repository[exampleRepo], Is.EqualTo(exampleJob)); userConsole.Verify(c => c.ReadInput(repoName, false), Times.Never); userConsole.Verify(c => c.ReadInput(jenkinsJob, false), Times.Never); }
public void ChangeShapeHasCorrectData(string creature) { Assert.That(table, Contains.Key(creature)); var datas = table[creature] .Select(helper.ParseEntry) .Where(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == FeatConstants.SpecialQualities.ChangeShape); var testCaseSpecialQualityDatas = GetTestCaseData(creature); foreach (var data in datas) { var testCaseData = testCaseSpecialQualityDatas.First(d => d[DataIndexConstants.SpecialQualityData.FeatNameIndex] == FeatConstants.SpecialQualities.ChangeShape); Assert.That(Convert.ToInt32(testCaseData[DataIndexConstants.SpecialQualityData.FrequencyQuantityIndex]), Is.Not.Negative, "TEST CASE: Frequency Quantity"); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FrequencyTimePeriodIndex], Is.Not.Empty, "TEST CASE: Frequency Time Period"); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.FocusIndex], Is.Not.Empty, "TEST CASE: Focus"); Assert.That(testCaseData[DataIndexConstants.SpecialQualityData.PowerIndex], Is.EqualTo(0.ToString()), "TEST CASE: Power"); Assert.That(Convert.ToInt32(data[DataIndexConstants.SpecialQualityData.FrequencyQuantityIndex]), Is.Not.Negative, "XML: Frequency Quantity"); Assert.That(data[DataIndexConstants.SpecialQualityData.FrequencyTimePeriodIndex], Is.Not.Empty, "XML: Frequency Time Period"); Assert.That(data[DataIndexConstants.SpecialQualityData.FocusIndex], Is.Not.Empty, "XML: Focus"); Assert.That(data[DataIndexConstants.SpecialQualityData.PowerIndex], Is.EqualTo(0.ToString()), "XML: Power"); } }
public async Task TestNestedThrowsAreOk() { const string exceptionKey = "Key"; try { try { using (LogContext.PushProperty(exceptionKey, "Value")) { await Task.Yield(); throw new Exception("Explosions, ahh"); } } catch (Exception exception) { _logger.Error(exception, "First line of defense"); throw; } } catch (Exception exception) { _logger.Error(exception, "Last line of defense"); } Assert.That(_logEventSink.Events.Count, Is.EqualTo(2)); var firstEvent = _logEventSink.Events[0]; Assert.That(firstEvent.Properties, Contains.Key(exceptionKey)); var firstEventPropertyValue = (ScalarValue)firstEvent.Properties[exceptionKey]; Assert.That(firstEventPropertyValue.Value, Is.EqualTo("Value")); var secondEvent = _logEventSink.Events[1]; Assert.That(secondEvent.Properties, Contains.Key(exceptionKey)); var secondEventPropertyValue = (ScalarValue)secondEvent.Properties[exceptionKey]; Assert.That(secondEventPropertyValue.Value, Is.EqualTo("Value")); }
public void Formatting() { foreach (var yaml in RoleRegistry.LoadYaml()) { var children = yaml.Children; Assert.That(children, Contains.Key((YamlNode)"id")); Assert.That(children["id"].AsString().Length, Is.Positive); Assert.That(children, Contains.Key((YamlNode)"team")); var team = children["team"].AsString(); Assert.That(team.Length, Is.Positive); Assert.NotNull(TeamRegistry.Default[team]); Assert.That(children, Contains.Key((YamlNode)"categories")); var categoryNames = children["categories"]; Assert.That(categoryNames.AsStringList().Count, Is.Positive); foreach (var category in (YamlSequenceNode)categoryNames) { Assert.NotNull(CategoryRegistry.Default[category.AsString()]); } Assert.That(children, Contains.Key((YamlNode)"color")); Assert.That(children["color"].AsColor(), Is.Not.EqualTo(Color.Empty)); } }
public void Subtract_SubtractsPairedKeys() { // Arrange var dict1 = new Dictionary<string, double> { ["a"] = 4, ["b"] = 5, ["c"] = 5, }; var dict2 = new Dictionary<string, double> { ["a"] = 2, ["b"] = 1, ["c"] = 5, }; // Act var resultDict = dict1.Subtract(dict2); // Assert Assert.Multiple(() => { Assert.That(resultDict["a"], Is.EqualTo(2)); Assert.That(resultDict["b"], Is.EqualTo(4)); Assert.That(resultDict, new NotConstraint(Contains.Key("c"))); }); }
public void TestHashCode() { var s1 = new GameInfo() { Hero = "Link", Child = "Pip", Animal = Animal.Ricky }; var s2 = new GameInfo() { Hero = "Link", Child = "Pip~", Animal = Animal.Ricky }; var s3 = new GameInfo() { Hero = "Link", Child = "Pip", Animal = Animal.None }; var s4 = new GameInfo() { Hero = "Link", Child = "Pip", Animal = Animal.Ricky }; // Because using mutable objects as a key is an awesome idea... var dict = new Dictionary <GameInfo, bool> { { s1, true }, { s2, true } }; Assert.That(dict, !Contains.Key(s3)); Assert.That(dict, Contains.Key(s4)); }
public void Lookup_Instrument_By_Unique_Id() { /* * Look up an instrument that already exists in the instrument master by a * unique id, in this case an OpenFigi, and also return a list of aliases */ var lookedUpInstruments = _instrumentsApi.GetInstruments( FigiScheme, new List <string> { "BBG000C6K6G9" }, propertyKeys: new List <string> { IsinPropertyKey, SedolPropertyKey }); Assert.That(lookedUpInstruments.Values, Contains.Key("BBG000C6K6G9")); var instrument = lookedUpInstruments.Values["BBG000C6K6G9"]; Assert.That(instrument.Name, Is.EqualTo("VODAFONE GROUP PLC")); var identifiers = instrument.Properties.OrderBy(i => i.Key).ToList(); Assert.That(identifiers[0].Key, Is.EqualTo(IsinPropertyKey)); Assert.That(identifiers[0].Value.LabelValue, Is.EqualTo("GB00BH4HKS39")); Assert.That(identifiers[1].Key, Is.EqualTo(SedolPropertyKey)); Assert.That(identifiers[1].Value.LabelValue, Is.EqualTo("BH4HKS3")); }
public void ApiException_Converts_To_ValidationProblemDetails_MaxLength() { try { var testScope = new string('a', 100); var testCode = new string('b', 100); var _ = _factory.Api <PortfoliosApi>().GetPortfolio(testScope, testCode); } catch (ApiException e) { Assert.That(e.IsValidationProblem, Is.True, "Response should indicate that there was a validation error with the request"); // An ApiException.ErrorContent thrown because of a request validation contains a JSON serialized LusidValidationProblemDetails if (e.TryGetValidationProblemDetails(out var errorResponse)) { //Should identify that there was a validation error with the code Assert.That(errorResponse.Errors, Contains.Key("code")); Assert.That(errorResponse.Errors["code"].Single(), Is.EqualTo("Values for the field code must be non-zero in length and have no more than 64 characters. For more information please consult the documentation.")); //Should identify that there was a validation error with the scope Assert.That(errorResponse.Errors, Contains.Key("scope")); Assert.That(errorResponse.Errors["scope"].Single(), Is.EqualTo("Values for the field scope must be non-zero in length and have no more than 64 characters. For more information please consult the documentation.")); Assert.That(errorResponse.Detail, Does.Match("One or more elements of the request were invalid.*")); Assert.That(errorResponse.Name, Is.EqualTo("InvalidRequestFailure")); } else { Assert.Fail("The request should have failed due to a validation error, and the validation details should be returned"); } } }
public static void KeyAndValueMatch(Dictionary <string, JsonElement> resultDic, string key, object value) { Assert.That(resultDic, Contains.Key(key)); var valueType = value.GetType(); if (valueType == typeof(string)) { Assert.That(resultDic[key].GetString(), Is.EqualTo(value)); } else if (valueType == typeof(bool)) { Assert.That(resultDic[key].GetBoolean(), Is.EqualTo(value)); } else if (valueType == typeof(int)) { Assert.That(resultDic[key].GetInt32(), Is.EqualTo(value)); } else if (valueType == typeof(long)) { Assert.That(resultDic[key].GetInt64(), Is.EqualTo(value)); } else if (valueType == typeof(JsonValueKind)) { Assert.That(resultDic[key].ValueKind, Is.EqualTo(value)); } else { Assert.Fail("Unhandled value type"); } }