Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add result tests
  • Loading branch information
annelo-msft committed Jan 4, 2024
commit 5655d1a7c6b052fa87274699de8caecd0cfcd9e0
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.IO;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;

namespace System.ClientModel;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using ClientModel.Tests.Mocks;
using NUnit.Framework;
using System.ClientModel.Primitives;

namespace System.ClientModel.Tests.Exceptions;

public class ClientRequestExceptionTests
{
//[Test]
//public void CanCreateFromResponse()
//{

//}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,58 @@ public void CanCreateDerivedOptionalResult()
Assert.IsFalse(result.HasValue);
Assert.AreEqual(response.Status, result.GetRawResponse().Status);
}

#endregion

#region ClientResult<T>

[Test]
public void CannotCreateClientResultOfTFromNullResponse()
{
object value = new();

Assert.Throws<ArgumentNullException>(() => new MockClientResult<object>(value, null!));
Assert.Throws<ArgumentNullException>(() =>
{
OptionalClientResult<object> result = ClientResult.FromValue(value, null!);
});
}

[Test]
public void CannotCreateClientResultOfTFromNullValue()
{
MockPipelineResponse response = new MockPipelineResponse();

Assert.Throws<ArgumentNullException>(() => new MockClientResult<object>(null!, response));
Assert.Throws<ArgumentNullException>(() =>
{
OptionalClientResult<object> result = ClientResult.FromValue<object>(null!, response);
});
}

[Test]
public void CanCreateDerivedResult()
{
string value = "hello";

PipelineResponse response = new MockPipelineResponse(200);
DerivedClientResult<string> result = new(value, response);

Assert.IsTrue(result.HasValue);
Assert.AreEqual(value, result.Value);
Assert.AreEqual(response.Status, result.GetRawResponse().Status);
}

#endregion

#region Helpers

internal class DerivedClientResult<T> : ClientResult<T>
{
public DerivedClientResult(T value, PipelineResponse response) : base(value, response)
{
}
}

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel;
using System.ClientModel.Primitives;

namespace ClientModel.Tests.Mocks;

public class MockClientResult<T> : ClientResult<T>
{
public MockClientResult(T value, PipelineResponse response) : base(value, response)
{
}
}