Ejemplo n.º 1
0
            public void Returns_True_When_Both_Sides_Are_Null()
            {
                SomeValue x1 = null;
                SomeValue x2 = null;

                (x1 == x2).Should().BeTrue();
            }
Ejemplo n.º 2
0
            public void Inverts_The_Equal_Operator()
            {
                var x1 = new SomeValue();
                var x2 = new SomeValue();

                (x1 != x2).Should().BeFalse();
            }
    static void Main()
    {
        SomeValue val1 = new SomeValue(1);
        SomeValue val2 = new SomeValue(2);

        Console.WriteLine(val1.CompareTo(val2));
    }
Ejemplo n.º 4
0
        public void SomeCastsToOptionTest()
        {
            SomeValue <string> some = "Hello";
            Option <string>    opt  = some;

            Assert.True(opt.IsSome && opt.IfNone("") == "Hello");
        }
        private void HandlePropertyChangedEvent(object sender, PropertyChangedEventArgs e)
        {
            if (string.Equals(e.PropertyName, nameof(SomeValueText), StringComparison.InvariantCultureIgnoreCase))
            {
                double result;
                if (Double.TryParse(SomeValueText, out result))
                {
                    // Do not allow property changed event
                    if (SomeValue != result)
                    {
                        SomeValue = result;
                        Debug.WriteLine($"New value of SomeValue = {SomeValue}");
                    }
                }
            }

            if (string.Equals(e.PropertyName, nameof(SomeValue), StringComparison.InvariantCultureIgnoreCase))
            {
                double result;
                if (Double.TryParse(SomeValueText, out result))
                {
                    if (result != SomeValue)
                    {
                        SomeValueText = SomeValue.ToString();
                        Debug.WriteLine($"New value of SomeValueText = {SomeValueText}");
                    }
                }
                else
                {
                    SomeValueText = SomeValue.ToString();
                    Debug.WriteLine($"New value of SomeValueText = {SomeValueText}");
                }
            }
        }
Ejemplo n.º 6
0
 public void DoStuffWithNullContextWillThrow(NameAppender sut, SomeValue sv)
 {
     // Fixture setup
     // Exercise system and verify outcome
     Assert.Throws <ArgumentNullException>(() =>
                                           sut.DoStuff(sv, null));
     // Teardown
 }
Ejemplo n.º 7
0
 public Collector(SomeValue <CollectorId> id, SomeValue <string> name, SomeValue <TenantId> tenant, SomeValue <UserId> assignedBy, Instant dateAssigned)
 {
     Id              = id;
     Name            = name;
     CurrentTenant   = tenant;
     AssignedBy      = assignedBy;
     InstantAssigned = dateAssigned;
 }
Ejemplo n.º 8
0
 public void NotNullReferenceTypeTest()
 {
     Assert.Throws <ValueIsNullException>(
         () =>
     {
         SomeValue <string> str = null;
     });
 }
Ejemplo n.º 9
0
            public void Returns_False_For_Other_Types()
            {
                var valueObject = new SomeValue();

                var result = valueObject.Equals(new SomeOtherValue());

                result.Should().BeFalse();
            }
        // PUT api/values/5
        public HttpResponseMessage Put(int id, SomeValue value)
        {
            var resp = Request.CreateResponse(HttpStatusCode.OK);

            resp.Headers.Add("Foo", "foo");
            resp.Headers.Add("Bar", "bar");
            return(resp);
        }
Ejemplo n.º 11
0
            public void Returns_False_When_Compared_To_Null()
            {
                var valueObject = new SomeValue();

                var result = valueObject.Equals(null);

                result.Should().BeFalse();
            }
Ejemplo n.º 12
0
        void Foo(SomeValue <string> value)
        {
            if (value.Value == null)
            {
                failwith <Unit>("Value should never be null");
            }

            string doesItImplicitlyCastBackToAString = value;
        }
Ejemplo n.º 13
0
        public void DoStuffWillReverseMessage(Reverser sut, SomeValue value)
        {
            // Fixture setup
            var expectedResult = new string(value.Message.Reverse().ToArray());
            // Exercise system
            var result = sut.DoStuff(value, null);

            // Verify outcome
            Assert.Equal(expectedResult, result);
            // Teardown
        }
    int IComparable.CompareTo(object obj)
    {
        if (obj is SomeValue)
        {
            SomeValue other = (SomeValue)obj;

            return(n - other.n);
        }
        else
        {
            throw new ArgumentException("Wrong Type!");
        }
    }
Ejemplo n.º 15
0
        public void DoStuffWillAppendContextNameToMessage(NameAppender sut, SomeValue value, string contextName, Mock <ISomeContext> contextStub)
        {
            // Fixture setup
            var expectedResult = contextName + value.Message;

            contextStub.SetupGet(ctx => ctx.Name).Returns(contextName);
            // Exercise system
            var result = sut.DoStuff(value, contextStub.Object);

            // Verify outcome
            Assert.Equal <string>(expectedResult, result);
            // Teardown
        }
Ejemplo n.º 16
0
        private void ValueTypeBoxUnbox()
        {
            var    val  = new SomeValue();
            Object val1 = val;
            Object val2 = val;

            Console.WriteLine(Object.ReferenceEquals(val1, val2));
            val.Run();         // call(this somevalue)
            val.GetType();     // call(this object)
            val.ToString();    // callvirt
            Monitor.Enter(val);
            Monitor.Exit(val); // Error Not Same Object
        }
Ejemplo n.º 17
0
        public void DoStuffWillThrowOnNullValue()
        {
            // Fixture setup
            var fixture = new Fixture();

            fixture.Inject(Enumerable.Empty <IAddIn>());
            var       sut       = fixture.CreateAnonymous <AddInClient>();
            SomeValue nullValue = null;

            // Exercise system
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.DoStuff(nullValue));
            // Verify outcome (expected exception)
            // Teardown
        }
Ejemplo n.º 18
0
        public void DoStuffWithNameAppenderAndReverserWillReturnCorrectResult()
        {
            // Fixture setup
            var sut = new AddInClient(new IAddIn[] { new NameAppender(), new Reverser() });

            var value = new SomeValue {
                Message = "Ploeh"
            };
            // Exercise system
            var result = sut.DoStuff(value);

            // Verify outcome
            Assert.Equal <string>("heolPtneilCnIddA", result.Message);
            // Teardown
        }
Ejemplo n.º 19
0
        public void DoStuffWillReturnValueWithMessageConstructedByAddIns()
        {
            // Fixture setup
            var fixture         = new Fixture();
            var expectedMessage = fixture.CreateAnonymous("Message");

            var addInStub1 = new Mock <IAddIn>();

            addInStub1.Setup(ai => ai.DoStuff(It.IsAny <SomeValue>(), It.IsAny <ISomeContext>())).Returns(fixture.CreateAnonymous("Message"));

            var addInStub2 = new Mock <IAddIn>();

            addInStub2.Setup(ai => ai.DoStuff(It.IsAny <SomeValue>(), It.IsAny <ISomeContext>())).Returns(expectedMessage);

            fixture.Register <IEnumerable <IAddIn> >(() => new[] { addInStub1.Object, addInStub2.Object });

            var sut = fixture.CreateAnonymous <AddInClient>();
            // Exercise system
            SomeValue result = fixture.Get((SomeValue sv) => sut.DoStuff(sv));

            // Verify outcome
            Assert.Equal <string>(expectedMessage, result.Message);
            // Teardown
        }
Ejemplo n.º 20
0
 public ViewModel()
 {
     _value = new SomeValue();
 }
Ejemplo n.º 21
0
            public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
            {
                SomeValue someValue = (SomeValue)value;

                writer.WriteValue(someValue.Text);
            }
Ejemplo n.º 22
0
        // No output, as we avoid checking the precondition, if it is redundant
        public static int GetSomeValue(SomeValue s)
        {
            Contract.Requires(Enum.IsDefined(typeof(SomeValue), s));

            return(s.GetHashCode());
        }
 // PUT api/values/5
 public void Put(int id, SomeValue value)
 {
 }
 // POST api/values
 public void Post(SomeValue value)
 {
 }
Ejemplo n.º 25
0
 public void Returns_False_For_Derived_Types()
 {
     var valueObject = new SomeValue();
 }
Ejemplo n.º 26
0
 void Greet(SomeValue <string> arg)
 {
     Console.WriteLine(arg);
 }
 public int CompareTo(SomeValue other)
 {
     return(n - other.n);
 }
Ejemplo n.º 28
0
        public void DoStuffWillReturnContextName(SomeClass sut, string expectedName, Mock <ISomeContext> contextStub, SomeValue sv)
        {
            // Fixture setup
            contextStub.SetupGet(ctx => ctx.Name).Returns(expectedName);
            // Exercise system
            var result = sut.DoStuff(sv, contextStub.Object);

            // Verify outcome
            Assert.Equal(expectedName, result);
            // Teardown
        }
Ejemplo n.º 29
0
 public GetAttributesAttribute(SomeValue TargetEnum)
 {
 }