Exemplo n.º 1
0
        public void OrThrowWithText_DoesNotThrowIfSome()
        {
            var testValue = 0;

            Assert.DoesNotThrow(() => testValue = EOption <int> .Some(1).OrThrow("Test"));
            Assert.That(testValue, Is.EqualTo(1));
        }
Exemplo n.º 2
0
        public void ConvertToEOption_None()
        {
            var maybe = Maybe <string> .None;
            EOption <string> EOption = maybe.ToEOption();

            Assert.That(EOption.IsNone, Is.True);
        }
Exemplo n.º 3
0
        public void Equals_Option()
        {
            var aEOption = EOption <int> .Some(4);

            var aOption = Option <int, Exception> .Some(4);

            var bEOption = EOption <int> .None;
            var bOption  = Option <int, Exception> .None;

            var exception = new ArgumentException();
            var cEOption  = EFailable <int> .Failure(exception);

            var cOption = Failable <int, Exception> .Failure(exception);

            Assert.That(aEOption.GetHashCode(), Is.EqualTo(aOption.GetHashCode()), "HashCode not correct (Success-Case)");
            Assert.That(bEOption.GetHashCode(), Is.EqualTo(bOption.GetHashCode()), "HashCode not correct (None-Case)");
            Assert.That(cEOption.GetHashCode(), Is.EqualTo(cOption.GetHashCode()), "HashCode not correct (Failure-Case)");

            Assert.That(aEOption, Is.EqualTo(aOption), "EOption-Equals is buggy! (Some-Case)");
            Assert.That(bEOption, Is.EqualTo(bOption), "EOption-Equals is buggy! (None-Case)");
            Assert.That(cEOption, Is.EqualTo(cOption), "EOption-Equals is buggy! (Failure-Case)");
            Assert.That(aOption, Is.EqualTo(aEOption), "Implementation of Option is not accepting EOption! (Some-Case)");
            Assert.That(bOption, Is.EqualTo(bEOption), "Implementation of Option is not accepting EOption! (None-Case)");
            Assert.That(cOption, Is.EqualTo(cEOption), "Implementation of Option is not accepting EOption! (Failure-Case)");

            Assert.That(aEOption, Is.Not.EqualTo(bOption));  //sanity-checks
            Assert.That(cOption, Is.Not.EqualTo(bEOption));
        }
Exemplo n.º 4
0
        public void OrThrow_DoesNotThrowIfSome()
        {
            var testValue = ""; //to be overwritten by "happy"

            Assert.DoesNotThrow(() => testValue = EOption <string> .Some("HAPPY").OrThrow());
            Assert.That(testValue, Is.EqualTo("HAPPY"));
        }
Exemplo n.º 5
0
        public async Task <AppResult <Rate_vw> > SelectOptionAsync(EOption option)
        {
            switch (option)
            {
            case EOption.USD_EUR:
                return(await _service.GetRateAsync(ECurrency.USD, ECurrency.EUR));

            case EOption.USD_GBP:
                return(await _service.GetRateAsync(ECurrency.USD, ECurrency.GBP));

            case EOption.EUR_USD:
                return(await _service.GetRateAsync(ECurrency.EUR, ECurrency.USD));

            case EOption.EUR_GBP:
                return(await _service.GetRateAsync(ECurrency.EUR, ECurrency.GBP));

            case EOption.GPB_USD:
                return(await _service.GetRateAsync(ECurrency.GBP, ECurrency.USD));

            case EOption.GPB_EUR:
                return(await _service.GetRateAsync(ECurrency.GBP, ECurrency.EUR));

            default:
                throw new InvalidOptionException();
            }
        }
Exemplo n.º 6
0
        public void TryGet_Result_Some()
        {
            var EOption = EOption <string> .Some("blub");

            EOption.TryGetValue(out var s);

            Assert.That(s, Is.EqualTo("blub"));
        }
Exemplo n.º 7
0
        public void ConstructFailure_ErrorNotNull()
        {
            var testValue = EOption <object> .Failure(new ArgumentException());

            Assert.That(testValue.IsSome, Is.False);
            Assert.That(testValue.IsNone, Is.False);
            Assert.That(testValue.IsFailure, Is.True);
        }
Exemplo n.º 8
0
        public void TryGet_Value_Failure()
        {
            var EOption = EOption <string> .Failure(new ArgumentException());

            EOption.TryGetValue(out var s);

            Assert.IsNull(s);
        }
Exemplo n.º 9
0
        public void FlatMapToDifferentType()
        {
            var one = EOption <int> .Some(1);

            EOption <string> onePlusOne = one.FlatMap(i => EOption <string> .Some($"{i}+1=2"));

            Assert.That(onePlusOne.OrThrow(), Is.EqualTo("1+1=2"));
        }
Exemplo n.º 10
0
        public void Map_NestingInMap()
        {
            var flag1 = EOption <bool> .Some(true);

            var result = flag1.Map(_ => EOption <bool> .Some(true));

            Assert.That(result.Or(EOption <bool> .Failure(new ArgumentException("disgusting"))).Or(false), Is.True);
        }
Exemplo n.º 11
0
        public void Map_Success()
        {
            var original = EOption <string> .Some("hallo");

            var result = original.Map(s => s += " welt");

            Assert.That(result.OrThrow, Is.EqualTo("hallo welt"));
        }
Exemplo n.º 12
0
        public void Equals_DifferentTypeInequalForFailure()
        {
            var x = EOption <int> .Failure(new ArgumentException());

            var y = EOption <object> .Failure(new ArgumentException());

            Assert.That(x.Equals(y), Is.False);
        }
Exemplo n.º 13
0
        public void ConstructNone_ViaNullableWithoutValue()
        {
            var testValue = EOption <int> .From(new int?());

            Assert.That(testValue.IsNone, Is.True);
            Assert.That(testValue.IsSome, Is.False);
            Assert.That(testValue.IsFailure, Is.False);
        }
Exemplo n.º 14
0
        public void Equals_FailedEqualObjects()
        {
            var x = EOption <int> .Failure(new ArgumentException());

            var y = EOption <int> .Failure(new ArgumentException());

            Assert.That(x.Equals(y), Is.False);
        }
Exemplo n.º 15
0
        public void Equals_SomeInequal()
        {
            var x = EOption <int> .Some(4);

            var y = EOption <int> .Some(5);

            Assert.That(x.Equals(y), Is.False);
        }
Exemplo n.º 16
0
        public void ConstructSome_ViaActualValue()
        {
            var testValue = EOption <object> .Some(new object());

            Assert.That(testValue.IsSome, Is.True);
            Assert.That(testValue.IsNone, Is.False);
            Assert.That(testValue.IsFailure, Is.False);
        }
Exemplo n.º 17
0
        public void ConvertToMaybe_Failure()
        {
            var EOption = EOption <string> .Failure(new ArgumentException());

            var maybe = EOption.ToMaybe();

            Assert.That(maybe.IsNone, Is.True);
        }
Exemplo n.º 18
0
        public void ConvertToEOption_Success()
        {
            var EFailable = EFailable <string> .Success("hubba");

            EOption <string> EOption = EFailable.ToEOption();

            Assert.That(EOption.IsSome, Is.True);
        }
Exemplo n.º 19
0
        public void ConstructNone_ViaSomeIsNull()
        {
            var testValue = EOption <object> .From(null);

            Assert.That(testValue.IsSome, Is.False);
            Assert.That(testValue.IsNone, Is.True);
            Assert.That(testValue.IsFailure, Is.False);
        }
Exemplo n.º 20
0
 public FileWriter(string fileName, EOption typeOfFile, string ftpLogin = "", string ftpPassword = "")
 {
     _typeOfFile = typeOfFile.ToString();
     _login      = ftpLogin;
     _password   = ftpPassword;
     _fileNameWithoutExtension = fileName;
     _content = "Message here";
 }
Exemplo n.º 21
0
        public void ConvertToEOption_Failure()
        {
            var EFailable = EFailable <string> .Failure(new ArgumentException( "abc" ));

            EOption <string> EOption = EFailable.ToEOption();

            Assert.That(EOption.IsFailure, Is.True);
        }
Exemplo n.º 22
0
        public void ConvertToEOption_Some()
        {
            var maybe = Maybe <string> .Some("hubba");

            EOption <string> EOption = maybe.ToEOption();

            Assert.That(EOption.IsSome, Is.True);
        }
Exemplo n.º 23
0
        public void ConvertToFailable_Failure()
        {
            var EOption = EOption <string> .Failure(new ArgumentException("msg"));

            var failable = EOption.ToFailable(new ArgumentException("notMsg")); //different exception text!

            Assert.That(failable.IsFailure, Is.True);
            Assert.That(failable.FailureOrThrow().Message, Is.EqualTo("msg"));
        }
Exemplo n.º 24
0
        public void AddOption(EOption aOption, byte[] aValue)
        {
            List <byte> option = new List <byte>();

            option.Add((byte)aOption);
            option.Add((byte)aValue.Length);
            option.AddRange(aValue);
            iOptions.AddRange(option);
        }
Exemplo n.º 25
0
        public void ConvertToEFailable_Some()
        {
            var EOption = EOption <string> .Some("hallo");

            var failable = EOption.ToEFailable(new ArgumentException());

            Assert.That(failable.IsSuccess, Is.True);
            Assert.That(failable.OrThrow, Is.EqualTo("hallo"));
        }
Exemplo n.º 26
0
        public void ConvertToOption_Failure()
        {
            var EOption = EOption <string> .Failure(new ArgumentException( "msg" ));

            Option <string, Exception> option = EOption.ToOption();

            Assert.That(option.IsFailure, Is.True);
            Assert.That(option.FailureOrThrow().Message, Is.EqualTo("msg"));
        }
Exemplo n.º 27
0
        public void ConvertToOption_Some()
        {
            var EOption = EOption <string> .Some("hallo");

            var option = EOption.ToOption();

            Assert.That(option.IsSome, Is.True);
            Assert.That(option.OrThrow, Is.EqualTo("hallo"));
        }
Exemplo n.º 28
0
        public void OrConvertToFailable_Failure()
        {
            var eoption = EOption <int> .Failure(new ArgumentException( "msg" ));

            var failable = eoption.OrToFailable(456);

            Assert.That(failable.IsFailure, Is.True);
            Assert.That(failable.FailureOrThrow().Message, Is.EqualTo("msg"));
        }
Exemplo n.º 29
0
        public void OrConvertToFailable_Some()
        {
            var eoption = EOption <int> .Some(123);

            var failable = eoption.OrToFailable(456);

            Assert.That(failable.IsSuccess, Is.True);
            Assert.That(failable.OrThrow, Is.EqualTo(123));
        }
Exemplo n.º 30
0
        public void ConvertToEFailable_Failure()
        {
            var EOption = EOption <string> .Failure(new ArgumentException( "msg" ));

            EFailable <string> failable = EOption.ToEFailable(new ArgumentException("to-be-used-on-none!"));

            Assert.That(failable.IsFailure, Is.True);
            Assert.That(failable.FailureOrThrow().Message, Is.EqualTo("msg"));
        }