Skip to content

Commit

Permalink
Fix EnumDiscriminator Test (#5123)
Browse files Browse the repository at this point in the history
* Update EnumDiscriminatorTests.cs

* Update payload-multipart.cs

* Update EnumDiscriminatorTests.cs

* Update EnumDiscriminatorTests.cs
  • Loading branch information
mcgallan authored Oct 25, 2024
1 parent dc071e0 commit a532712
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Net.Http;
using System.Threading.Tasks;
using _Type.Model.Inheritance.EnumDiscriminator;
using _Type.Model.Inheritance.EnumDiscriminator.Models;
using AutoRest.TestServer.Tests.Infrastructure;
using Azure;
using Microsoft.Extensions.Hosting;
using NUnit.Framework;

namespace CadlRanchProjects.Tests
Expand Down Expand Up @@ -64,20 +68,28 @@ public Task GetFixedEnum() => Test(async (host) =>
[Test]
public Task GetFixedModelMissingDiscriminator() => Test(async (host) =>
{
var response = await new EnumDiscriminatorClient(host, null).GetExtensibleModelMissingDiscriminatorAsync();
var response = await new EnumDiscriminatorClient(host, null).GetFixedModelMissingDiscriminatorAsync();
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.IsNotInstanceOf<Golden>(response.Value);
Assert.AreEqual(10, response.Value.Weight);
Assert.IsNotInstanceOf<Cobra>(response.Value);
Assert.AreEqual(10, response.Value.Length);
});

[Test]
public Task GetFixedModelWrongDiscriminator() => Test(async (host) =>
public Task GetFixedModelWrongDiscriminator() => Test((host) =>
{
var response = await new EnumDiscriminatorClient(host, null).GetExtensibleModelWrongDiscriminatorAsync();
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.IsNotInstanceOf<Golden>(response.Value);
Assert.AreEqual(8, response.Value.Weight);
var client = new EnumDiscriminatorClient(host, null);
var exception = Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => client.GetFixedModelWrongDiscriminatorAsync());
Assert.IsTrue(exception.Message.Contains("wrongKind"));
return Task.CompletedTask;
});

[Test]
public Task GetFixedModelWrongDiscriminator_Protocol() => Test(async (host) =>
{
var client = new EnumDiscriminatorClient(host, null);
var context = new RequestContext();
var response = await client.GetFixedModelWrongDiscriminatorAsync(context);
Assert.AreEqual(200, response.Status);
});
}
}
15 changes: 5 additions & 10 deletions test/CadlRanchProjects.Tests/payload-multipart.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.IO;
using System.Threading.Tasks;
using AutoRest.TestServer.Tests.Infrastructure;
Expand All @@ -12,6 +11,7 @@ public class PayloadMultipartTests : CadlRanchTestBase
{
private string SamplePngPath = Path.Combine(CadlRanchServer.GetSpecDirectory(), "assets", "image.png");
private string SampleJpgPath = Path.Combine(CadlRanchServer.GetSpecDirectory(), "assets", "image.jpg");
private string SampleJpgPath2 = Path.Combine(CadlRanchServer.GetSpecDirectory(), "assets", "hello.jpg");

[Test]
public Task Payload_Multipart_FormData_Basic() => Test(async (host) =>
Expand Down Expand Up @@ -44,17 +44,12 @@ public Task Payload_Multipart_FormData_BinaryArrayParts() => Test(async (host) =
});

[Test]
[Ignore("The Cadl Ranch's cadl-ranch-specs/assets folder does not contain a hello.jpg file with the mimetype \"image/jpg\", so this test lacks the necessary input.")]
public Task Payload_Multipart_FormData_CheckFileNameAndContentType() => Test(async (host) =>
{
Address addressX = new Address("X");
var profileImage = System.IO.File.OpenRead(SampleJpgPath);
var pictures = new Stream[]
{
System.IO.File.OpenRead(SamplePngPath),
System.IO.File.OpenRead(SamplePngPath)
};
ComplexPartsRequest data = new ComplexPartsRequest("123", addressX, profileImage, pictures);
var response = await new MultiPartClient(host, null).GetFormDataClient().FileArrayAndBasicAsync(data);
var profileImage = System.IO.File.OpenRead(SampleJpgPath2);
MultiPartRequest input = new MultiPartRequest("123", profileImage);
var response = await new MultiPartClient(host, null).GetFormDataClient().CheckFileNameAndContentTypeAsync(input);
Assert.AreEqual(204, response.Status);
});

Expand Down

0 comments on commit a532712

Please sign in to comment.