public AndConstraint <EditableValueAssertions <T> > NotBe(EditableValue <T> expected, string because = "", params object[] becauseArgs) { Execute.Assertion .ForCondition(!Subject.Equals(expected)) .BecauseOf(because, becauseArgs) .FailWith("Expected {context:EditableValue<T>} to be {0}{reason}, but found {1}.", expected, Subject); return(new AndConstraint <EditableValueAssertions <T> >(this)); }
public AndConstraint <NullableEditableValueAssertions <T> > Be(EditableValue <T>?expected, string because = "", params object[] becauseArgs) { Execute.Assertion .ForCondition(Subject == expected) .BecauseOf(because, becauseArgs) .FailWith("Expected {context:Address} to be {0}{reason}, but found {1}.", expected, Subject); return(new AndConstraint <NullableEditableValueAssertions <T> >(this)); }
public BoobData(BoobData other) { this.enabled = other.enabled; this.force = other.force; this.gravity = other.gravity; this.originalEnabled = other.originalEnabled; this.originalGravity = other.originalGravity; this.originalForce = other.originalForce; }
public void GenericUpdate_ShouldBeUpdate() { // arrange var sut = EditableValue.Update(Fixture.Create <int>()); // act // assert sut.Should().BeUpdateVariant(because: "{0} is created using generic Update<T>() method and should be treated as 'update'", sut); }
public void DomesticNoAction_ShouldBeNoAction() { // arrange var sut = EditableValue <int> .NoAction(); // act // assert sut.Should().BeNoActionVariant(because: "{0} is created using domestic static NoAction() method and should be treated as 'noAction'", sut); }
public void GenericNoAction_ShouldBeNoAction() { // arrange var sut = EditableValue.NoAction(Fixture.Create <int>()); // act // assert sut.Should().BeNoActionVariant(because: "{0} is created using generic NoAction<T>() method and should be treated as 'noAction'", sut); }
public void ParameterlessConstructor_ShouldBeNoAction() { // arrange var sut = new EditableValue <int>(); // act // assert sut.Should().BeNoActionVariant(because: "{0} is created using parameterless constructor and should be treated as 'noAction'", sut); }
public void ConstructorWithValue_ShouldBeUpdate() { // arrange var sut = new EditableValue <int>(Fixture.Create <int>()); // act // assert sut.Should().BeUpdateVariant(because: "{0} is created using constructor with value parameter and should be treated as 'update'", sut); }
private static IEnumerable <EditableValue <string> > GetSerializeTestData() { yield return(EditableValue <string> .NoAction()); yield return(EditableValue <string> .Update(null)); yield return(EditableValue <string> .Update(string.Empty)); yield return(EditableValue <string> .Update(System.Guid.NewGuid().ToString())); }
public void NoAction_ShouldNotCallMapper() { // arrange var sut = EditableValue <int> .NoAction(); // act Action map = () => sut.Map <int>(_ => throw new InvalidOperationException()); // assert map.Should().NotThrow(because: "mapping 'noAction' should not call mapper function"); }
public void NoAction_ShouldMapToNoAction() { // arrange var sut = EditableValue <int> .NoAction(); // act var result = sut.Map(e => e.ToString()); // assert result.Should().BeNoActionVariant(); }
public void UpdateOfDifferentValues_ShouldNotBeEqual() { // arrange var update1 = EditableValue <int> .Update(1); var update2 = EditableValue <int> .Update(2); // act // assert update1.Equals(update2).Should().BeFalse(); update2.Equals(update1).Should().BeFalse(); }
public void UpdateOfSameValues_ShouldBeEqual() { // arrange var update1 = EditableValue <int> .Update(1); var update2 = EditableValue <int> .Update(1); // act // assert update1.Equals(update2).Should().BeTrue(); update2.Equals(update1).Should().BeTrue(); }
public void NoActionAndUpdateOfDefaultValue_ShouldNotBeEqual() { // arrange var noAction = EditableValue <int> .NoAction(); var update = EditableValue <int> .Update(default(int)); // act // assert noAction.Equals(update).Should().BeFalse(); update.Equals(noAction).Should().BeFalse(); }
public void NoActionAndDefaultEditableValue_ShouldBeEqual() { // arrange var noAction = EditableValue <int> .NoAction(); var @default = default(EditableValue <int>); // act // assert noAction.Equals(@default).Should().BeTrue(); @default.Equals(noAction).Should().BeTrue(); }
public void NoAction_ShouldNotCallUpdateFunc() { // arrange var sut = EditableValue <int> .NoAction(); // act Action match = () => sut.Match( update: _ => throw new InvalidOperationException(), noAction: () => State.NoAction); // assert match.Should().NotThrow(because: "matching 'noAction' should not call 'update' function"); }
public void Update_ShouldMatch() { // arrange var sut = EditableValue <int> .Update(Fixture.Create <int>()); // act var result = sut.Match( update: _ => State.Update, noAction: () => State.NoAction); // assert result.Should().Be(State.Update); }
public void Update_ShouldNotCallNoActionFunc() { // arrange var sut = EditableValue <int> .Update(Fixture.Create <int>()); // act Action match = () => sut.Match( update: _ => State.Update, noAction: () => throw new InvalidOperationException()); // assert match.Should().NotThrow(because: "matching 'update' should not call 'noAction' function"); }
public void NoAction_ShouldMatch() { // arrange var sut = EditableValue <int> .NoAction(); // act var result = sut.Match( update: _ => State.Update, noAction: () => State.NoAction); // assert result.Should().Be(State.NoAction); }
public void Update_ShouldMapToUpdate() { // arrange int originalValue = Fixture.Create <int>(); var sut = EditableValue <int> .Update(originalValue); Func <int, string> map = e => e.ToString(); string expectedValue = map(originalValue); // act var result = sut.Map(map); // assert result.Should().BeUpdateOf(expectedValue); }
public void SerializeAndDeserialize_ShouldBeIdempotent(EditableValue <string> originalValue) { // arrange var converter = new EditableValueJsonConverter <string>(); // act string serializedValue1 = JsonConvert.SerializeObject(originalValue, converter); var deserializedValue1 = JsonConvert.DeserializeObject <EditableValue <string> >(serializedValue1, converter); string serializedValue2 = JsonConvert.SerializeObject(deserializedValue1, converter); var deserializedValue2 = JsonConvert.DeserializeObject <EditableValue <string> >(serializedValue2, converter); // assert deserializedValue1.Should().Be(originalValue); deserializedValue2.Should().Be(originalValue); deserializedValue2.Should().Be(deserializedValue1); serializedValue2.Should().Be(serializedValue1); }
public bool TryBuild(out EditableValue <T> result) { T value = Value; string state = State; if (string.IsNullOrEmpty(state) || string.Equals(state, Constants.Editable_NoActionState, StringComparison.OrdinalIgnoreCase)) { result = EditableValue <T> .NoAction(); return(true); } if (string.Equals(state, Constants.Editable_UpdateState, StringComparison.OrdinalIgnoreCase)) { result = EditableValue <T> .Update(value); return(true); } result = default(EditableValue <T>); return(false); }
public override void WriteJson(JsonWriter writer, EditableValue <T> editable, JsonSerializer serializer) { writer.WriteStartObject(); string state = editable.Match( update: _ => Constants.Editable_UpdateState, noAction: () => Constants.Editable_NoActionState); writer.WritePropertyName(Constants.StatePropertyName); writer.WriteValue(state); var(isUpdate, value) = editable.Match( update: e => (true, e), noAction: () => (false, default(T))); if (isUpdate) { writer.WritePropertyName(Constants.ValuePropertyName); serializer.Serialize(writer, value); } writer.WriteEndObject(); }
void LoadParameters() { ConfigNode savenode; if (getVessel.mainBody.atmosphereDepth > 0) DestinationHeight = getVessel.mainBody.atmosphereDepth + 10000; else DestinationHeight = getVessel.mainBody.timeWarpAltitudeLimits[1] + 10000; DestinationHeight /= 1000; try { savenode = ConfigNode.Load(ConfigFilename(getVessel)); if (savenode != null) { if (ConfigNode.LoadObjectFromConfig(this, savenode)) Log("Vessel loaded from " + ConfigFilename(getVessel)); else Log("Vessel NOT loaded from " + ConfigFilename(getVessel)); } } catch (Exception ex) { Log("Vessel Load error " + ex.GetType()); } }
public void CalculateSettings(Vessel vessel,bool UseBest=false) { stagestats.RequestUpdate(this); double TWR = 0; for (int i = stagestats.atmoStats.Length - 1; i >= 0; i--) { double stagetwr = stagestats.atmoStats[i].StartTWR(vessel.mainBody.GeeASL); if (stagetwr > 0) { if (vessel.StageHasSolidEngine(i)) TWR = (stagetwr + stagestats.atmoStats[i].MaxTWR(vessel.mainBody.GeeASL))/2.3; else TWR = stagetwr; break; } } if (TWR > 1.2) { TWR -= 1.2; TurnAngle = Mathf.Clamp((float)(10 + TWR * 9), 10, 80); StartSpeed = Mathf.Clamp((float)(100 - TWR * 45), 10, 100); } double guessTurn, guessSpeed; if (UseBest && launchdb.BestSettings(out guessTurn,out guessSpeed)) { StartSpeed = guessSpeed; TurnAngle = guessTurn; } else if (launchdb.GuessSettings(out guessTurn, out guessSpeed)) { StartSpeed = guessSpeed; TurnAngle = guessTurn; } APTimeFinish = 40; APTimeStart = 40; Sensitivity = 0.2; if (vessel.mainBody.atmosphereDepth > 0) DestinationHeight = vessel.mainBody.atmosphereDepth + 10000; else DestinationHeight = vessel.mainBody.timeWarpAltitudeLimits[1] + 10000; DestinationHeight /= 1000; Roll = -90; Inclination = 0; PressureCutoff = 2500; SaveParameters(); }
public EditableValueAssertions(EditableValue <T>?subject) { Subject = subject; }
// Constructors. // public TestObject() { this._firstName = new EditableValue <string>(""); this._lastName = new EditableValue <string>(""); }
public override EditableValue <T> ReadJson(JsonReader reader, Type objectType, EditableValue <T> existingValue, bool hasExistingValue, JsonSerializer serializer) { var builder = new EditableValueBuilder <T>(); if (reader.TokenType == JsonToken.StartObject) { while (reader.Read() && reader.TokenType != JsonToken.EndObject) { if (reader.TryReadPropertyAs(Constants.StatePropertyName, serializer, e => e.ReadAsString(), out var stateValue)) { builder.State = stateValue; } else if (reader.TryDeserializeProperty(Constants.ValuePropertyName, serializer, out T valueObj)) { builder.Value = valueObj; } } } if (!builder.TryBuild(out var editable)) { throw new InvalidOperationException($"Could not read {typeof(EditableValue<T>)} from JSON."); } return(editable); }
public NullableEditableValueAssertions(EditableValue <T>?subject) : base(subject) { }
public TestObject(InitContext ctx) { this._firstName = new EditableValue <string>(""); this._lastName = new EditableValue <string>(""); }
public TestObject(InitContext ctx) { this._firstName = new EditableValue<string>(""); this._lastName = new EditableValue<string>(""); }
// Constructors. // public TestObject() { this._firstName = new EditableValue<string>(""); this._lastName = new EditableValue<string>(""); }
public static NullableEditableValueAssertions <T> Should <T>(this EditableValue <T>?actualValue) => new NullableEditableValueAssertions <T>(actualValue);
public static EditableValueAssertions <T> Should <T>(this EditableValue <T> actualValue) => new EditableValueAssertions <T>(actualValue);