fix tests

This commit is contained in:
Фролов 2021-12-07 13:44:00 +05:00
parent 819bc82227
commit 498489b231
2 changed files with 20 additions and 19 deletions

View File

@ -7,6 +7,7 @@ using Moq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Security.Claims; using System.Security.Claims;
using System.Threading;
using Xunit; using Xunit;
namespace AsbCloudWebApi.Tests.ControllersTests namespace AsbCloudWebApi.Tests.ControllersTests
@ -31,7 +32,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
new WellDepthToDayDto { WellDepth = 3000.0, BitDepth = 3000.0, Date = DateTime.Now } new WellDepthToDayDto { WellDepth = 3000.0, BitDepth = 3000.0, Date = DateTime.Now }
}; };
analyticsService.Setup(s => s.GetWellDepthToDay(It.IsAny<int>())) analyticsService.Setup(s => s.GetWellDepthToDayAsync(It.IsAny<int>(), CancellationToken.None).Result)
.Returns(depthToDayDtos); .Returns(depthToDayDtos);
wellService.Setup(s => s.IsCompanyInvolvedInWell(It.IsAny<int>(), It.IsAny<int>())) wellService.Setup(s => s.IsCompanyInvolvedInWell(It.IsAny<int>(), It.IsAny<int>()))
@ -54,7 +55,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
[Fact] [Fact]
public void It_should_return_depth_to_day_analytics() public void It_should_return_depth_to_day_analytics()
{ {
var result = controller.GetWellDepthToDay(1); var result = controller.GetWellDepthToDayAsync(1).Result;
var okResult = result as OkObjectResult; var okResult = result as OkObjectResult;
Assert.NotNull(okResult); Assert.NotNull(okResult);
@ -63,7 +64,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
[Fact] [Fact]
public void It_should_return_correct_count_depth_to_day_analytics() public void It_should_return_correct_count_depth_to_day_analytics()
{ {
var result = controller.GetWellDepthToDay(1); var result = controller.GetWellDepthToDayAsync(1).Result;
var okResult = result as OkObjectResult; var okResult = result as OkObjectResult;
var resultCount = ((List<WellDepthToDayDto>)okResult.Value).Count; var resultCount = ((List<WellDepthToDayDto>)okResult.Value).Count;
@ -83,7 +84,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
HttpContext = new DefaultHttpContext() { User = user } HttpContext = new DefaultHttpContext() { User = user }
}; };
var result = emptyUserController.GetWellDepthToDay(1); var result = emptyUserController.GetOperationsByWellAsync(1).Result;
var forbidResult = result as ForbidResult; var forbidResult = result as ForbidResult;
Assert.NotNull(forbidResult); Assert.NotNull(forbidResult);
@ -110,7 +111,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
HttpContext = new DefaultHttpContext() { User = user } HttpContext = new DefaultHttpContext() { User = user }
}; };
var result = newControllerInstance.GetWellDepthToDay(1); var result = newControllerInstance.GetWellDepthToDayAsync(1).Result;
var forbidResult = result as ForbidResult; var forbidResult = result as ForbidResult;
Assert.NotNull(forbidResult); Assert.NotNull(forbidResult);
@ -121,7 +122,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
{ {
var emptyAnalyticsService = new Mock<ITelemetryAnalyticsService>(); var emptyAnalyticsService = new Mock<ITelemetryAnalyticsService>();
emptyAnalyticsService.Setup(s => s.GetWellDepthToDay(It.IsAny<int>())) emptyAnalyticsService.Setup(s => s.GetWellDepthToDayAsync(It.IsAny<int>(), CancellationToken.None).Result)
.Returns(new List<WellDepthToDayDto>()); .Returns(new List<WellDepthToDayDto>());
var newControllerInstance = new TelemetryAnalyticsController(emptyAnalyticsService.Object, var newControllerInstance = new TelemetryAnalyticsController(emptyAnalyticsService.Object,
@ -137,7 +138,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
HttpContext = new DefaultHttpContext() { User = user } HttpContext = new DefaultHttpContext() { User = user }
}; };
var result = newControllerInstance.GetWellDepthToDay(1); var result = newControllerInstance.GetWellDepthToDayAsync(1).Result;
var notFoundResult = result as NoContentResult; var notFoundResult = result as NoContentResult;
Assert.NotNull(notFoundResult); Assert.NotNull(notFoundResult);
@ -148,7 +149,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
{ {
var emptyAnalyticsService = new Mock<ITelemetryAnalyticsService>(); var emptyAnalyticsService = new Mock<ITelemetryAnalyticsService>();
emptyAnalyticsService.Setup(s => s.GetWellDepthToDay(It.IsAny<int>())) emptyAnalyticsService.Setup(s => s.GetWellDepthToDayAsync(It.IsAny<int>(), CancellationToken.None).Result)
.Returns(value: null); .Returns(value: null);
var newControllerInstance = new TelemetryAnalyticsController(emptyAnalyticsService.Object, var newControllerInstance = new TelemetryAnalyticsController(emptyAnalyticsService.Object,
@ -164,7 +165,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
HttpContext = new DefaultHttpContext() { User = user } HttpContext = new DefaultHttpContext() { User = user }
}; };
var result = newControllerInstance.GetWellDepthToDay(1); var result = newControllerInstance.GetWellDepthToDayAsync(1).Result;
var notFoundResult = result as NoContentResult; var notFoundResult = result as NoContentResult;
Assert.NotNull(notFoundResult); Assert.NotNull(notFoundResult);

View File

@ -16,16 +16,16 @@ namespace ConsoleApp1
{ {
public static void Main(/*string[] args*/) public static void Main(/*string[] args*/)
{ {
var options = new DbContextOptionsBuilder<AsbCloudDbContext>() //var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
.UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") // .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
.Options; // .Options;
using var db = new AsbCloudDbContext(options); //using var db = new AsbCloudDbContext(options);
var cacheDb = new CacheDb(); //var cacheDb = new CacheDb();
var telemetryService = new TelemetryService(db, new TelemetryTracker(cacheDb), cacheDb); //var telemetryService = new TelemetryService(db, new TelemetryTracker(cacheDb), cacheDb);
var wellService = new WellService(db, telemetryService, cacheDb); //var wellService = new WellService(db, telemetryService, cacheDb);
var wellOptsStat = new OperationsStatService(db, cacheDb, wellService); //var wellOptsStat = new OperationsStatService(db, cacheDb, wellService);
var tvd = wellOptsStat.GetTvdAsync(1, default).Result; //var tvd = wellOptsStat.GetTvdAsync(1, default).Result;
Print(tvd); //Print(tvd);
} }
private static void Print(IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd) private static void Print(IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd)