Skip to content

Commit

Permalink
.Net: Remove unused fields in unit tests (#2055)
Browse files Browse the repository at this point in the history
### Description
Identifying and removing some fields that are unused in Skills unit
tests. In some cases, error values are being checked, but the object in
question has never been accessed, nor had an opportunity to generate an
exception.

### Contribution Checklist
- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#dev-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
  • Loading branch information
shawncal committed Jul 18, 2023
1 parent b8d873d commit f622bfe
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Skills.Document;
using Microsoft.SemanticKernel.Skills.Document.FileSystem;
using Moq;
Expand All @@ -16,8 +13,6 @@ namespace SemanticKernel.Skills.UnitTests.Document;

public class DocumentSkillTests
{
private readonly SKContext _context = new(new ContextVariables(), NullMemory.Instance, null, NullLogger.Instance);

[Fact]
public async Task ReadTextAsyncSucceedsAsync()
{
Expand All @@ -43,7 +38,6 @@ public async Task ReadTextAsyncSucceedsAsync()

// Assert
Assert.Equal(expectedText, actual);
Assert.False(this._context.ErrorOccurred);
fileSystemConnectorMock.VerifyAll();
documentConnectorMock.VerifyAll();
}
Expand Down Expand Up @@ -75,7 +69,6 @@ public async Task AppendTextAsyncFileExistsSucceedsAsync()
await target.AppendTextAsync(anyText, anyFilePath);

// Assert
Assert.False(this._context.ErrorOccurred);
fileSystemConnectorMock.VerifyAll();
documentConnectorMock.VerifyAll();
}
Expand Down Expand Up @@ -109,7 +102,6 @@ public async Task AppendTextAsyncFileDoesNotExistSucceedsAsync()
await target.AppendTextAsync(anyText, anyFilePath);

// Assert
Assert.False(this._context.ErrorOccurred);
fileSystemConnectorMock.VerifyAll();
documentConnectorMock.VerifyAll();
}
Expand Down
27 changes: 1 addition & 26 deletions dotnet/src/Skills/Skills.UnitTests/MsGraph/CalendarSkillTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,16 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Skills.MsGraph;
using Microsoft.SemanticKernel.Skills.MsGraph.Models;
using Moq;
using SemanticKernel.Skills.UnitTests.XunitHelpers;
using SemanticKernel.UnitTests;
using Xunit;
using Xunit.Abstractions;

namespace SemanticKernel.Skills.UnitTests.MsGraph;

public class CalendarSkillTests : IDisposable
public class CalendarSkillTests
{
private readonly XunitLogger<SKContext> _logger;

public CalendarSkillTests(ITestOutputHelper output)
{
this._logger = new XunitLogger<SKContext>(output);
}

[Fact]
public async Task AddEventAsyncSucceedsAsync()
{
Expand Down Expand Up @@ -260,19 +250,4 @@ public async Task AddEventAsyncWithoutSubjectFailsAsync()
ArgumentException e = Assert.IsType<ArgumentException>(context.LastException);
Assert.Equal("subject", e.ParamName);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
this._logger.Dispose();
}
}

public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,14 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Skills.MsGraph;
using Moq;
using SemanticKernel.Skills.UnitTests.XunitHelpers;
using Xunit;
using Xunit.Abstractions;

namespace SemanticKernel.Skills.UnitTests.MsGraph;

public class CloudDriveSkillTests : IDisposable
public class CloudDriveSkillTests
{
private readonly XunitLogger<SKContext> _logger;
private readonly SKContext _context;
private bool _disposedValue = false;

public CloudDriveSkillTests(ITestOutputHelper output)
{
this._logger = new XunitLogger<SKContext>(output);
this._context = new SKContext(new ContextVariables(), NullMemory.Instance, null, this._logger, CancellationToken.None);
}

[Fact]
public async Task UploadSmallFileAsyncSucceedsAsync()
{
Expand Down Expand Up @@ -88,24 +74,4 @@ public async Task GetFileContentAsyncSucceedsAsync()
Assert.Equal(expectedContent, actual);
connectorMock.VerifyAll();
}

protected virtual void Dispose(bool disposing)
{
if (!this._disposedValue)
{
if (disposing)
{
this._logger.Dispose();
}

this._disposedValue = true;
}
}

public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
9 changes: 0 additions & 9 deletions dotnet/src/Skills/Skills.UnitTests/MsGraph/EmailSkillTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Skills.MsGraph;
using Moq;
using Xunit;
using static Microsoft.SemanticKernel.Skills.MsGraph.EmailSkill;

namespace SemanticKernel.Skills.UnitTests.MsGraph;

public class EmailSkillTests
{
private readonly SKContext _context = new();

[Fact]
public async Task SendEmailAsyncSucceedsAsync()
{
Expand All @@ -29,14 +25,10 @@ public async Task SendEmailAsyncSucceedsAsync()
string anySubject = Guid.NewGuid().ToString();
string anyRecipient = Guid.NewGuid().ToString();

this._context.Variables.Set(Parameters.Recipients, anyRecipient);
this._context.Variables.Set(Parameters.Subject, anySubject);

// Act
await target.SendEmailAsync(anyContent, anyRecipient, anySubject);

// Assert
Assert.False(this._context.ErrorOccurred);
connectorMock.VerifyAll();
}

Expand Down Expand Up @@ -92,7 +84,6 @@ public async Task GetMyEmailAddressAsyncSucceedsAsync()

// Assert
Assert.Equal(anyEmailAddress, actual);
Assert.False(this._context.ErrorOccurred);
connectorMock.VerifyAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,14 @@
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Skills.MsGraph;
using Moq;
using SemanticKernel.Skills.UnitTests.XunitHelpers;
using Xunit;
using Xunit.Abstractions;

namespace SemanticKernel.Skills.UnitTests.MsGraph;

public class OrganizationHierarchySkillTests : IDisposable
public class OrganizationHierarchySkillTests
{
private readonly XunitLogger<SKContext> _logger;
private readonly SKContext _context;
private bool _disposedValue = false;

public OrganizationHierarchySkillTests(ITestOutputHelper output)
{
this._logger = new XunitLogger<SKContext>(output);
this._context = new SKContext(logger: this._logger, cancellationToken: CancellationToken.None);
}

[Fact]
public async Task GetMyDirectReportsEmailAsyncSucceedsAsync()
{
Expand Down Expand Up @@ -82,24 +69,4 @@ public async Task GetMyManagerNameAsyncSucceedsAsync()
Assert.Equal(anyManagerName, actual);
connectorMock.VerifyAll();
}

protected virtual void Dispose(bool disposing)
{
if (!this._disposedValue)
{
if (disposing)
{
this._logger.Dispose();
}

this._disposedValue = true;
}
}

public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Skills.MsGraph;
using Microsoft.SemanticKernel.Skills.MsGraph.Models;
using Moq;
Expand All @@ -14,8 +13,6 @@ namespace SemanticKernel.Skills.UnitTests.MsGraph;

public class TaskListSkillTests
{
private readonly SKContext _context = new();

private readonly TaskManagementTaskList _anyTaskList = new(
id: Guid.NewGuid().ToString(),
name: Guid.NewGuid().ToString());
Expand Down Expand Up @@ -46,7 +43,6 @@ public async Task AddTaskAsyncNoReminderSucceedsAsync()
await target.AddTaskAsync(anyTitle);

// Assert
Assert.False(this._context.ErrorOccurred);
connectorMock.VerifyAll();
}

Expand All @@ -71,7 +67,6 @@ public async Task AddTaskAsyncWithReminderSucceedsAsync()
await target.AddTaskAsync(anyTitle, anyReminder);

// Assert
Assert.False(this._context.ErrorOccurred);
connectorMock.VerifyAll();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Skills.OpenAPI;
using Xunit;

Expand Down Expand Up @@ -47,9 +46,6 @@ public void GetJsonElementValueSucceeds(string jsonPath, string expected)
{
var target = new JsonPathSkill();

ContextVariables variables = new(Json);
SKContext context = new(variables);

string actual = target.GetJsonElementValue(Json, jsonPath);

Assert.Equal(expected, actual, StringComparer.OrdinalIgnoreCase);
Expand All @@ -63,9 +59,6 @@ public void GetJsonPropertyValueSucceeds(string jsonPath, string expected)
{
var target = new JsonPathSkill();

ContextVariables variables = new(Json);
SKContext context = new(variables);

string actual = target.GetJsonElements(Json, jsonPath);

Assert.Equal(expected, actual, StringComparer.OrdinalIgnoreCase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,14 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Skills.Web;
using Moq;
using SemanticKernel.Skills.UnitTests.XunitHelpers;
using Xunit;
using Xunit.Abstractions;

namespace SemanticKernel.Skills.UnitTests.Web;

public sealed class WebSearchEngineSkillTests : IDisposable
public sealed class WebSearchEngineSkillTests
{
private readonly SKContext _context;
private readonly XunitLogger<SKContext> _logger;

public WebSearchEngineSkillTests(ITestOutputHelper output)
{
this._logger = new XunitLogger<SKContext>(output);
this._context = new SKContext(logger: this._logger);
}

[Fact]
public async Task SearchAsyncSucceedsAsync()
{
Expand All @@ -42,12 +30,6 @@ public async Task SearchAsyncSucceedsAsync()
await target.SearchAsync(anyQuery);

// Assert
Assert.False(this._context.ErrorOccurred);
connectorMock.VerifyAll();
}

public void Dispose()
{
this._logger.Dispose();
}
}

This file was deleted.

Loading

0 comments on commit f622bfe

Please sign in to comment.