public void Should_add_location_header_to_the_message_when_response_contains_a_api_resource() { var apiResource = new TestResource(); var response = new NotModifiedResponse(apiResource); AssertExpectedStatus(response); response.Headers.Location.ShouldEqual(apiResource.Location); }
public void Should_add_content_to_message_when_its_a_typed_response_message() { var apiResource = new TestResource(); var response = new ConflictResponse<TestResource>(apiResource); AssertExpectedStatus(response); response.Headers.Location.ShouldEqual(apiResource.Location); response.Content.ShouldNotBeNull(); response.Content.ObjectType.ShouldEqual(typeof(TestResource)); }
[Test] public void CloneResource() { Random rnd = new Random(); TestResource source = new TestResource(rnd); TestResource target = source.DeepClone(); Assert.AreEqual(source, target); Assert.AreNotSame(source, target); Assert.AreNotSame(source.TestReferenceList, target.TestReferenceList); }
public void ShouldCreateResourceInTarget() { using (var channel = new SynchronizationChannel<TestResource>(_testSource, _testTarget)) { channel.Open(); _testResource = new TestResource(1); _testSource.Create(_testResource); Assert.AreEqual(_testResource, _testTarget.Get(1)); } }
public async Task<IActionResult> ResourceBasedPolicyTest() { var resource = new TestResource(); if (!await authorizationService.AuthorizeAsync(User, resource, ResourceOperations.Read)) { return new ChallengeResult(); } return View(); }
public void CanSerializeResource() { var original = TestResource.Default1(); var json = JsonConvert.SerializeObject(original, _settings); const string expected = TestResource.SerializedDefault1; var deserialized = JsonConvert.DeserializeObject <TestResource>(json, _settings); json.ShouldNotBeNullOrWhiteSpace(); json.ShouldBe(expected, StringCompareShould.IgnoreCase); original.ShouldBe(deserialized); }
private void AssertCanLoadProject(string resourceName) { string fileName = Path.GetFileNameWithoutExtension(resourceName); using (TestResource file = new TestResource(resourceName)) { VSProject project = new VSProject(file.Path); Assert.AreEqual(fileName, project.Name); Assert.AreEqual(Path.GetFullPath(file.Path), project.ProjectPath); Assert.AreEqual(fileName.ToLower(), Path.GetFileNameWithoutExtension(project.Configs[0].Assemblies[0].ToString().ToLower())); } }
public void GetTemplatedLinkOnResource_WithValidResourceWithNullLinksWithMultipleTemplate_ExpectException() { var resource = new TestResource(); var ex = Should.Throw <MissingLinkException>(() => resource.GetLink(DefaultRel, new Dictionary <string, object> { { DefaultToken1, DefaultToken1Value }, { DefaultToken2, DefaultToken2Value } })); _logger.WriteLine(ex.Message); }
public void FromSolutionWithDisabledProject() { using (new TestResource("csharp-sample.csproj", @"csharp-sample\csharp-sample.csproj")) using (new TestResource("csharp-debug-only.csproj", @"csharp-debug-only\csharp-debug-only.csproj")) using (TestResource file = new TestResource("solution-with-disabled-project.sln")) { IProject project = _loader.LoadFrom(file.Path); Assert.AreEqual(2, project.ConfigNames.Count); Assert.AreEqual(2, project.GetTestPackage("Release").TestFiles.Count, "Release should have 2 assemblies"); Assert.AreEqual(1, project.GetTestPackage("Debug").TestFiles.Count, "Debug should have 1 assembly"); } }
public void PicksUpCorrectOutputPath(string resourceName, string configuration, string expectedOutputPath) { using (TestResource file = new TestResource(resourceName)) { IProject project = _loader.LoadFrom(file.Path); var package = project.GetTestPackage(configuration); // adjust for difference between Linux/Win: var basePath = package.Settings["BasePath"].ToString().Replace('\\', '/'); Assert.That(basePath.EndsWith(expectedOutputPath)); } }
public void TryGetTemplatedLinkOnResource_WithValidResourceWithNullLinksWithMultipleTemplate_ExpectNoExceptionAndNull() { var resource = new TestResource(); var actual = resource.TryGetLink(DefaultRel, new Dictionary <string, object> { { DefaultToken1, DefaultToken1Value }, { DefaultToken2, DefaultToken2Value } }); actual.ShouldBeNull(); }
public void FromSolutionWithNonNunitTestProject() { using (new TestResource("csharp-sample.csproj", NormalizePath(@"csharp-sample\csharp-sample.csproj"))) using (new TestResource("csharp-debug-only-no-nunit.csproj", NormalizePath(@"csharp-debug-only-no-nunit\csharp-debug-only-no-nunit.csproj"))) using (TestResource file = new TestResource("solution-with-non-nunit-project.sln")) { IProject project = _loader.LoadFrom(file.Path); Assert.AreEqual(2, project.ConfigNames.Count); Assert.AreEqual(2, project.GetTestPackage("Release").SubPackages.Count, "Release should have 2 assemblies"); Assert.AreEqual(2, project.GetTestPackage("Debug").SubPackages.Count, "Debug should have 2 assemblies"); } }
public void WithDependencies_ShouldReturnResourceWithoutAddingResourcesToDependsOnProperty_WhenNullPassed() { // Arrange var resource = new TestResource(); // Act var result = resource.WithDependencies(null); // Assert result.Should().BeSameAs(resource); result.DependsOn.Should().BeEmpty(); }
public void Dispose_Ignores_Running_Or_Queued_Tasks_That_Canceled_Or_Faulted() { // arrange TestResource testResource = new TestResource(); SharedResource <TestResource> sharedResource = new SharedResource <TestResource> ( resource: testResource, maxConcurrentUserCount: 1, isMaxConcurrentUserCountReadOnly: true ); // act const int taskCount = 1000; Task[] tasks = new Task[taskCount]; int normalTaskCount = 0; for (int i = 0; i < tasks.Length; i++) { int switchFactor = i % 3; if (switchFactor != 0 && switchFactor != 1) { normalTaskCount++; } CancellationTokenSource tokenSource = new CancellationTokenSource(); tasks[i] = sharedResource.UseAsync(p => { switch (switchFactor) { case 0: throw new InvalidOperationException("Test Exception"); case 1: tokenSource.Cancel(); tokenSource.Token.ThrowIfCancellationRequested(); break; default: p.Resource.IncreaseCounterNoThreadSafe(); break; } }, tokenSource.Token); } sharedResource.Dispose(); testResource.WaitUntilDisposedFor5Minutes(); // assert Assert.IsTrue(testResource.IsDisposed); Assert.IsTrue(testResource.Counter == normalTaskCount); }
public async Task WhenContentAndSendingHandlerTypesMismatchAndSuppressTypeException_ExpectResult() { var builder = CreateBuilder().WithResult(TestResource.Default1()).WithLink(MockUri); //act var actual = await builder.WithContent(TestRequest.Default1()) .AsPost() .Advanced .WithSuppressTypeMismatchExceptions().OnSendingWithContent <AlternateTestRequest>(ctx => { }).ResultAsync <TestResource>(); actual.ShouldNotBeNull(); }
public void WithTags_ShouldReturnResourceWithoutAddingTagsToTagsProperty_WhenNullPassed() { // Arrange var resource = new TestResource(); // Act var result = resource.WithTags(null); // Assert result.Should().BeSameAs(resource); result.Tags.Should().BeEmpty(); }
public async Task WhenDefaultResultAndResultTypesMismatchAndSuppressTypeException_ExpectNullResult() { var builder = CreateBuilder().WithError(TestResource.Default1()).WithLink(MockUri); //act var actual = await builder.WithDefaultResult(TestResource.Default1()) .Advanced.WithSuppressTypeMismatchExceptions() .OnException(context => context.ExceptionHandled = true) .ResultAsync <AlternateTestResource>(); actual.ShouldBeNull(); }
public void SetUp() { _items = new InternalTraceItemCollection(); _resourceA = new TestResource("HelloWorld.txt"); _resourceB = new TestResource("TextCode.txt"); _itemA = new ErrorItem(_resourceA.Path, 1); _itemB = new ErrorItem(_resourceB.Path, 2); return; }
public void RecourceCommandTest() { var res = new TestResource(); res.AssignId(); var id = res.Id; var retrivedRes = EntityManager.Instance.GetEntity <TestResource> (id); retrivedRes.GetCommandController().ExecuteCommand(new CommandData(id, null, "coreTest")); Assert.IsTrue(res.value == 5); }
public void EntityToDocument_NullEntity_CanBuild() { // Arrange TestResource entity = null; // Act var document = _builder.Build(entity, null, null); // Assert Assert.Null(document.Data); Assert.False(document.IsPopulated); }
public void Add_WhenKeyNotMatchKeyInResource_Throws() { var resource1V1 = new TestResource(1, 1); var partition = _sut.CreatePartition(); Action act1 = () => partition.Add(2, resource1V1); Action act2 = () => partition.Add(KeyValuePair.Create(2, resource1V1)); Action act3 = () => partition[2] = resource1V1; act1.Should().Throw <InvalidOperationException>(); act2.Should().Throw <InvalidOperationException>(); act3.Should().Throw <InvalidOperationException>(); }
private static Stream CreateCorruptedGZipStream(TestResource testResource, int offsetToCorrupt) { var stream = new MemoryStream(); using (var resourceStream = testResource.OpenResourceForReading()) { resourceStream.CopyTo(stream); } stream.Seek(offsetToCorrupt, SeekOrigin.Begin); stream.WriteByte(0xFF); stream.Seek(0, SeekOrigin.Begin); return(stream); }
public async Task ValidateStartSkipWait() { ManagementTestClient client = InstrumentClient(new ManagementTestClient()); TestResource rgOp = client.GetTestResource(); var testResourceOp = await rgOp.StartLroWrapperAsync(WaitUntil.Completed); Stopwatch timer = Stopwatch.StartNew(); TestResource testResource = await testResourceOp.WaitForCompletionAsync(); timer.Stop(); //method waits for 10 seconds so timer should easily be less than half of that if we skip Assert.IsTrue(timer.ElapsedMilliseconds < 5000, $"WaitForCompletion took {timer.ElapsedMilliseconds}ms"); }
public void AddResources_ShouldAddResourcesToResourcesProperty() { // Arrange var resource = new TestResource(); var childResource = new TestResource(); // Act resource.AddResources(new[] { childResource }); // Assert resource.Resources.Should().HaveCount(1); resource.Resources.First().Should().BeSameAs(childResource); }
public void WithUnmanagedCpp() { using (new TestResource("legacy-csharp-sample.csproj", NormalizePath(@"legacy-csharp-sample\legacy-csharp-sample.csproj"))) using (new TestResource("legacy-cpp-unmanaged.vcproj", NormalizePath(@"legacy-cpp-unmanaged\legacy-cpp-unmanaged.vcproj"))) using (TestResource file = new TestResource("solution-with-unmanaged-cpp.sln")) { IProject project = _loader.LoadFrom(file.Path); Assert.AreEqual(2, project.ConfigNames.Count); Assert.AreEqual(2, project.GetTestPackage("Debug").SubPackages.Count); Assert.AreEqual(2, project.GetTestPackage("Release").SubPackages.Count); } }
public void AddDependencies_ShouldAddResourcesToDependsOnProperty() { // Arrange var resource = new TestResource(); var dependency = new TestResource(); // Act resource.AddDependencies(new[] { dependency }); // Assert resource.DependsOn.Should().HaveCount(1); resource.DependsOn.First().Should().BeSameAs(dependency); }
public async Task GetAsync_WithIdFound() { using (var env = new TestEnvironment()) { Assert.That(env.Entities.Contains("test01"), Is.True); TestResource resource = await env.Service.GetAsync("test01"); Assert.That(resource, Is.Not.Null); Assert.That(resource.Id, Is.EqualTo("test01")); Assert.That(resource.Str, Is.EqualTo("old")); } }
public void ShouldAddItemToTarget() { var testSource = new InMemoryDataEndpoint<TestResource>(r => r.Id); var testTarget = new InMemoryDataEndpoint<TestResource>(r => r.Id); var testResource = new TestResource(1) { Description = "Test" }; testSource.Create(testResource); testTarget.AddSyncAction((e,r) => e.Get(e.IdentityResolver(r)) == null, (e, r) => e.Create(r), "Create"); var testChannel = new SynchronizationChannel<TestResource>(testSource, testTarget, true); testChannel.Open(); Assert.IsNotNull(testTarget.Get(1)); }
public void ResourceWithPropertiesWithParameters() { // Arrange var resource = new TestResource { Properties = new TestProperties { ParametersProp = new List <Parameter> { new Parameter { Name = "param1", Value = "value1" }, new Parameter { Name = "param2", Value = "value2" }, }, }, }; var template = new TestTemplate() .WithResources(resource); // Act var result = template.ToJson(_options); // Assert var expected = @"{ ""$schema"":""{DefaultTemplateSchema}"", ""contentVersion"":""{DefaultContentVersion}"", ""resources"": [ { ""type"": ""{DefaultResourceType}"", ""apiVersion"": ""{DefaultApiVersion}"", ""name"": """", ""properties"": { ""parametersProp"": { ""param1"": { ""value"": ""value1"" }, ""param2"": { ""value"": ""value2"" } } }, } ], ""outputs"": {} }"; JsonShouldBeEquivalent(expected, result); }
public void WithDependencies_WithParamsResources_ShouldAddResourceToResourcesPropertyAndReturnTemplate() { // Arrange var resource = new TestResource(); var dependency = new TestResource(); // Act var result = resource.WithDependencies(dependency); // Assert result.Should().BeSameAs(resource); result.DependsOn.Should().HaveCount(1); result.DependsOn.First().Should().BeSameAs(dependency); }
public void PicksUpCorrectMsBuildProperty(string resourceName, string expectedOutputFilename) { using (TestResource file = new TestResource(resourceName)) { IProject project = _loader.LoadFrom(file.Path); foreach (var config in project.ConfigNames) { TestPackage package = project.GetTestPackage(config); Assert.AreEqual(Path.GetFileName(package.SubPackages[0].FullName), expectedOutputFilename); } } }
public void PicksUpCorrectAssemblyName(string resourceName, string expectedAssemblyName) { using (TestResource file = new TestResource(resourceName)) { IProject project = _loader.LoadFrom(file.Path); foreach (var config in project.ConfigNames) { TestPackage package = project.GetTestPackage(config); Assert.That(Path.GetFileName(package.SubPackages[0].FullName) == expectedAssemblyName); } } }
private void AssertCanLoadVsProject(string resourceName) { string fileName = Path.GetFileNameWithoutExtension(resourceName); using (TestResource file = new TestResource(resourceName)) { NUnitProject project = converter.ConvertFrom(file.Path); Assert.AreEqual(fileName, project.Name); Assert.AreEqual(project.Configs[0].Name, project.ActiveConfigName); Assert.AreEqual(fileName.ToLower(), Path.GetFileNameWithoutExtension(project.Configs[0].Assemblies[0].ToLower())); Assert.IsTrue(project.IsLoadable, "Not loadable"); Assert.IsFalse(project.IsDirty, "Project should not be dirty"); } }
public void Should_add_content_to_message_when_its_a_typed_response_message() { var apiResource = new TestResource(); var response = new OkResponse<TestResource>(apiResource); AssertExpectedStatus(response); // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30 // The Location response-header field is used to redirect the recipient // to a location other than the Request-URI for completion of the request // or identification of a new resource. response.Headers.Location.ShouldBeNull(); response.Content.ShouldNotBeNull(); response.Content.ObjectType.ShouldEqual(typeof(TestResource)); }
public void Reference_WithResource_ShouldReturnCorrectlyFormattedFunctionString() { // Arrange const string name = "name"; var resource = new TestResource { Name = name }; // Act var result = Reference(resource); // Assert result.Should().Be($"reference('{name}')"); }
public void TearDown() { if (_resourceA != null) { _resourceA.Dispose(); _resourceA = null; } if (_resourceB != null) { _resourceB.Dispose(); _resourceB = null; } }
public void WithResources_WithParamsResources_ShouldAddResourceToResourcesPropertyAndReturnResource() { // Arrange var resource = new TestResource(); var childResource = new TestResource(); // Act var result = resource.WithResources(childResource); // Assert result.Should().BeSameAs(resource); result.Resources.Should().HaveCount(1); result.Resources.First().Should().BeSameAs(childResource); }
public void ShouldDeleteResourceInTargetWhenDeletedAtTarget() { using (var channel = new SynchronizationChannel<TestResource>(_testSource, _testTarget)) { // Arrange _testResource = new TestResource(1); channel.Open(); _testSource.Create(_testResource); // Act _testSource.Delete(_testResource); // Assert Assert.IsNull(_testTarget.Get(1)); } }
public void ShouldDeleteItemFromTarget() { var testSource = new InMemoryDataEndpoint<TestResource>(r => r.Id); var testTarget = new BatchListCleanupEndpointDecorator<TestResource>( new InMemoryDataEndpoint<TestResource>(r => r.Id)); var testResource = new TestResource(1) { Description = "Test" }; testTarget.Create(testResource); testTarget.AddSyncAction((e, r) => e.Get(e.IdentityResolver(r)) == null, (e, r) => e.Create(r), "Create"); var testChannel = new SynchronizationChannel<TestResource>(testSource, testTarget, true); testChannel.Opening += (s, e) => testTarget.Initialize(); testChannel.Closing += (s, e) => testTarget.Finish(); testChannel.Open(); Assert.IsNull(testTarget.Get(1)); Assert.IsFalse(testChannel.IsOpen); }
public void ShouldUpdateResourceInTargetWhenUpdatedLocal() { using (var channel = new SynchronizationChannel<TestResource>(_testSource, _testTarget)) { // Arrange _testResource = new TestResource(1) { CorrelationId = "1030" }; _testTarget.Create(_testResource); var changedResource = _testResource.Copy(); changedResource.Description = "Changed"; // Act channel.Open(); _testSource.Create(changedResource); // Assert var actualtTestResource = _testTarget.Get(1); Assert.AreEqual(_testResource, actualtTestResource); Assert.AreEqual("Changed", actualtTestResource.Description); } }
[Test] public void CloneContentRef() { Random rnd = new Random(); TestResource source = new TestResource(rnd); ContentRef<TestResource> sourceRef = new ContentRef<TestResource>(source, "SomeTestPath"); // Expect the Resource to be cloned TestResource target = source.DeepClone(); Assert.AreEqual(source, target); Assert.AreNotSame(source, target); // Expect only the reference to be cloned ContentRef<TestResource> targetRef = sourceRef.DeepClone(); Assert.AreEqual(sourceRef.Path, targetRef.Path); Assert.AreEqual(sourceRef.ResWeak, targetRef.ResWeak); // Let the source reference itself source.TestContentRef = source; Assert.AreSame(source, source.TestContentRef.ResWeak); // Expect the Resource to be cloned and holding a ContentRef to itself TestResource targetWithSelfRef = source.DeepClone(); Assert.AreSame(targetWithSelfRef, targetWithSelfRef.TestContentRef.ResWeak); }
private ITestResource GetObjectProxy(Action<TestResource> modifyOriginal = null) { var original = new TestResource { Info = "Hei", Children = { new TestResource { Info = "Childbar", Id = 1 }, new TestResource { Info = "ChildToRemove", Id = 2 } }, Spouse = new TestResource { Info = "Jalla", Id = 3 }, Friend = new TestResource { Info = "good friend", Id = 4 }, Id = 5 }; if (modifyOriginal != null) modifyOriginal(original); var proxy = (ITestResource)ObjectDeltaProxyBase.CreateDeltaProxy(original, this.typeMapper.GetClassMapping( typeof(ITestResource)), this.typeMapper, null); Assert.IsFalse(((Delta)proxy).IsDirty); return proxy; }
public void ShouldNotBreakPublishing() { _testTarget = new InMemoryDataEndpoint<TestResource>(t => t.Id); _testTarget.AddSyncAction(t => t.Deleted, (ds, t) => { throw new Exception("Ooops"); }, "Delete"); _testTarget.AddSyncAction(t => string.IsNullOrEmpty(t.CorrelationId), (ds, r) => ds.Create(r), "Create"); using (var channel = new SynchronizationChannel<TestResource>(_testSource, _testTarget)) { channel.Open(); _testResource = new TestResource(1); _testSource.Create(_testResource); _testSource.Delete(_testResource); var testResource2 = new TestResource(2); _testSource.Create(testResource2); Assert.AreEqual(testResource2, _testTarget.Get(2)); } }
private TestResource loadResource(ILibrary lib, string resName) { var res = new TestResource() { FullName = lib.Name + "::" + resName }; _loaded[res.FullName] = res; return res; }