forked from ddrilling/AsbCloudServer
Replace DetectableTelemetryBuilder by CommonExtensions.Copy()
This commit is contained in:
parent
e4a5ca69fb
commit
fb6126260f
@ -1,69 +0,0 @@
|
|||||||
using System;
|
|
||||||
using AsbCloudInfrastructure.Services.DetectOperations;
|
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Tests.Builders;
|
|
||||||
|
|
||||||
public class DetectableTelemetryBuilder
|
|
||||||
{
|
|
||||||
private DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
||||||
private float wellDepth = 300;
|
|
||||||
private float pressure = 15;
|
|
||||||
private float hookWeight = 20;
|
|
||||||
private float blockPosition = 20;
|
|
||||||
private float bitDepth = 151;
|
|
||||||
private float axialLoad = 19;
|
|
||||||
|
|
||||||
public DetectableTelemetryBuilder WithDateTime(DateTimeOffset newDateTime)
|
|
||||||
{
|
|
||||||
dateTime = newDateTime;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DetectableTelemetryBuilder WithWellDepth(float newWllDepth)
|
|
||||||
{
|
|
||||||
wellDepth = newWllDepth;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DetectableTelemetryBuilder WithPressure(float newPressure)
|
|
||||||
{
|
|
||||||
pressure = newPressure;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DetectableTelemetryBuilder WithHookWeight(float newHookWeight)
|
|
||||||
{
|
|
||||||
hookWeight = newHookWeight;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DetectableTelemetryBuilder WithBlockPosition(float newBlockPosition)
|
|
||||||
{
|
|
||||||
blockPosition = newBlockPosition;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DetectableTelemetryBuilder WithBitDepth(float newBitDepth)
|
|
||||||
{
|
|
||||||
bitDepth = newBitDepth;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DetectableTelemetryBuilder WithAxialLoad(float newAxialLoad)
|
|
||||||
{
|
|
||||||
axialLoad = newAxialLoad;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DetectableTelemetry Build() =>
|
|
||||||
new()
|
|
||||||
{
|
|
||||||
DateTime = dateTime,
|
|
||||||
WellDepth = wellDepth,
|
|
||||||
Pressure = pressure,
|
|
||||||
HookWeight = hookWeight,
|
|
||||||
BlockPosition = blockPosition,
|
|
||||||
BitDepth = bitDepth,
|
|
||||||
AxialLoad = axialLoad
|
|
||||||
};
|
|
||||||
}
|
|
19
AsbCloudWebApi.Tests/CommonExtensions.cs
Normal file
19
AsbCloudWebApi.Tests/CommonExtensions.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using Mapster;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Tests;
|
||||||
|
|
||||||
|
public static class CommonExtensions
|
||||||
|
{
|
||||||
|
public static T Copy<T>(this T obj)
|
||||||
|
{
|
||||||
|
var copy = obj.Adapt<T>();
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T Mutate<T>(this T obj, Action<T> mutation)
|
||||||
|
{
|
||||||
|
var copy = obj.Copy();
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using AsbCloudInfrastructure.Services.DetectOperations;
|
||||||
using AsbCloudInfrastructure.Services.DetectOperations.Detectors;
|
using AsbCloudInfrastructure.Services.DetectOperations.Detectors;
|
||||||
using AsbCloudWebApi.Tests.Builders;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Tests.Services.DetectedOperations.Detectors;
|
namespace AsbCloudWebApi.Tests.Services.DetectedOperations.Detectors;
|
||||||
@ -9,7 +9,14 @@ public class DetectorSlipsTimeTests
|
|||||||
{
|
{
|
||||||
private const int IdSlipsTime = 5011;
|
private const int IdSlipsTime = 5011;
|
||||||
|
|
||||||
private readonly DetectableTelemetryBuilder telemetryBuilder = new();
|
private readonly DetectableTelemetry telemetry = new() {
|
||||||
|
WellDepth = 300,
|
||||||
|
Pressure = 15,
|
||||||
|
HookWeight = 20,
|
||||||
|
BlockPosition = 20,
|
||||||
|
BitDepth = 151,
|
||||||
|
AxialLoad = 19,
|
||||||
|
};
|
||||||
|
|
||||||
private readonly DetectorSlipsTime sut = new();
|
private readonly DetectorSlipsTime sut = new();
|
||||||
|
|
||||||
@ -17,12 +24,10 @@ public class DetectorSlipsTimeTests
|
|||||||
public void DetectOperation_by_change_block_position_and_axial_load_less_hook_weight_is_success()
|
public void DetectOperation_by_change_block_position_and_axial_load_less_hook_weight_is_success()
|
||||||
{
|
{
|
||||||
//arrange
|
//arrange
|
||||||
var point0 = telemetryBuilder
|
var point0 = telemetry.Copy();
|
||||||
.Build();
|
|
||||||
|
|
||||||
var point1 = telemetryBuilder
|
var point1 = telemetry.Copy();
|
||||||
.WithBlockPosition(21)
|
point1.BlockPosition = 21;
|
||||||
.Build();
|
|
||||||
|
|
||||||
var telemetries = new[] { point0, point1 };
|
var telemetries = new[] { point0, point1 };
|
||||||
|
|
||||||
@ -38,16 +43,14 @@ public class DetectorSlipsTimeTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void DetectOperation_by_high_pressure_is_success()
|
public void DetectOperation_by_high_pressure_is_success()
|
||||||
{
|
{
|
||||||
//arrange
|
//arrange
|
||||||
var point0 = telemetryBuilder
|
var point0 = telemetry.Copy();
|
||||||
.Build();
|
|
||||||
|
|
||||||
var point1 = telemetryBuilder
|
var point1 = telemetry.Copy();
|
||||||
.WithBlockPosition(21)
|
point1.BlockPosition = 21;
|
||||||
.WithAxialLoad(30)
|
point1.AxialLoad = 30;
|
||||||
.WithHookWeight(20)
|
point1.HookWeight = 20;
|
||||||
.WithPressure(23)
|
point1.Pressure = 23;
|
||||||
.Build();
|
|
||||||
|
|
||||||
var telemetries = new[] { point0, point1 };
|
var telemetries = new[] { point0, point1 };
|
||||||
|
|
||||||
@ -63,14 +66,12 @@ public class DetectorSlipsTimeTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ValidateOperation_with_duration_more_30_minutes_is_invalid()
|
public void ValidateOperation_with_duration_more_30_minutes_is_invalid()
|
||||||
{
|
{
|
||||||
//arrange
|
//arrange
|
||||||
var point0 = telemetryBuilder
|
var point0 = telemetry.Copy();
|
||||||
.Build();
|
|
||||||
|
|
||||||
var point1 = telemetryBuilder
|
var point1 = telemetry.Copy();
|
||||||
.WithDateTime(DateTimeOffset.UtcNow.AddMinutes(30))
|
point1.BlockPosition = 21;
|
||||||
.WithBlockPosition(21)
|
point1.DateTime = DateTimeOffset.UtcNow.AddMinutes(30);
|
||||||
.Build();
|
|
||||||
|
|
||||||
var telemetries = new[] { point0, point1 };
|
var telemetries = new[] { point0, point1 };
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user