Exemple #1
0
        public void SetColor_And_LineTo_WithParameters_ShouldDrawLine()
        {
            var sw      = new StringWriter();
            var point1  = new Point(5, 10);
            var point2  = new Point(15, 10);
            var adapter = new ClassAdapter(sw);

            adapter.BeginDraw();
            adapter.SetColor(0x00FF00);
            adapter.MoveTo(point1.X, point1.Y);
            adapter.LineTo(point2.X, point2.Y);
            adapter.LineTo(point1.X, point1.Y);
            adapter.EndDraw();

            var expected = new StringWriter();

            expected.WriteLine("<draw>");
            expected.WriteLine($"  <line fromX={point1.X} fromY={point1.Y} toX={point2.X} toY={point2.Y}>");
            expected.WriteLine("    <color r=0 g=1 b=0 a=1/>");
            expected.WriteLine("  </line>");
            expected.WriteLine($"  <line fromX={point2.X} fromY={point2.Y} toX={point1.X} toY={point1.Y}>");
            expected.WriteLine("    <color r=0 g=1 b=0 a=1/>");
            expected.WriteLine("  </line>");
            expected.WriteLine("</draw>");

            Assert.AreEqual(expected.ToString(), sw.ToString());
        }
Exemple #2
0
        private static void TestClassAdapter()
        {
            ITarget t = new ClassAdapter();

            t.SayHelloworld();
            t.SayGoodbye();
        }
Exemple #3
0
        public void EndDraw_WithoutBeginDraw_ShouldThrowException()
        {
            var sw      = new StringWriter();
            var adapter = new ClassAdapter(sw);

            adapter.EndDraw();
        }
        public void GetMethodTest()
        {
            var b = ClassAdapter <A, B> .Adapt(new A { X = 100, Y = 50 });

            Assert.IsNotNull(b);
            Assert.IsTrue(b.Total == 150);
        }
Exemple #5
0
        public void LineTo_WithoutBeginDraw_ShouldThrowException()
        {
            var sw      = new StringWriter();
            var point   = new Point(5, 10);
            var adapter = new ClassAdapter(sw);

            adapter.LineTo(point.X, point.Y);
        }
Exemple #6
0
        public void BeginDraw_AfterBeginDraw_ShouldThrowException()
        {
            var sw      = new StringWriter();
            var adapter = new ClassAdapter(sw);

            adapter.BeginDraw();
            adapter.BeginDraw();
        }
        public void AddTest()
        {
            ClassAdapter adapter      = new ClassAdapter();
            string       expectedItem = "expected item";

            adapter.Add(expectedItem);
            Assert.Equal(expectedItem, adapter.Get(0));
        }
        public void RemoveTest()
        {
            ClassAdapter adapter      = new ClassAdapter();
            string       expectedItem = "expected item";

            adapter.Add(expectedItem);
            adapter.Remove(expectedItem);
            Assert.Throws <ArgumentOutOfRangeException>(() => adapter.Get(0));
        }
Exemple #9
0
        public void PropertyTest_NameWithUnderscore()
        {
            var e = ClassAdapter <C, E> .Adapt(new C { BClass = new B {
                                                           Total = 250
                                                       } });

            Assert.IsNotNull(e);
            Assert.IsTrue(e.BClass_Total == 250);
        }
        public void PropertyTest()
        {
            var d = ClassAdapter <C, D> .Adapt(new C { BClass = new B {
                                                           Total = 250
                                                       } });

            Assert.IsNotNull(d);
            Assert.IsTrue(d.BClassTotal == 250);
        }
        static void AdaptorExample()
        {
            ITarget target1 = new ClassAdapter();

            target1.Request();

            Target target2 = new ObjectAdapter();

            target2.Request();
        }
Exemple #12
0
    static void Main()
    {
        ITarget tClass = new ClassAdapter();

        tClass.Implement();

        Console.WriteLine("**************************");

        ITarget tObj = new ObjectAdapter(new Adaptee());

        tObj.Implement();
    }
        public void ConvertPrimitiveEntityToDTO()
        {
            var dto = ClassAdapter <Customer, CustomerDTO> .Adapt(GetCustomer());

            Assert.IsNotNull(dto);
            Assert.IsTrue(dto.Id == 1 &&
                          dto.Name == "Timuçin" &&
                          dto.Credit == 1542 &&
                          dto.IsActive &&
                          dto.DriverLicenceType == 'B' &&
                          dto.Debit == 100
                          );
        }
Exemple #14
0
        public void String_Is_Mapped_To_Enum()
        {
            var employee = new EmployeeWithStringEnum {
                Id = Guid.NewGuid(), Name = "Timuçin", Department = Departments.IT.ToString()
            };

            var dto = ClassAdapter <EmployeeWithStringEnum, EmployeeDTO> .Adapt(employee);

            dto.ShouldNotBeNull();

            dto.Id.ShouldEqual(employee.Id);
            dto.Name.ShouldEqual(employee.Name);
            dto.Department.ShouldEqual(Departments.IT);
        }
Exemple #15
0
        public static void PaintPictureOnMGRClassAdapter()
        {
            ClassAdapter  classAdapter = new ClassAdapter(Console.Out);
            CanvasPainter painter      = new CanvasPainter(classAdapter);

            try
            {
                classAdapter.BeginDraw();
                PaintPicture(painter);
                classAdapter.EndDraw();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #16
0
        public void Int_Is_Mapped_To_Enum()
        {
            TypeAdapterConfig <Employee, EmployeeDTO>
            .NewConfig();

            var employee = new Employee {
                Id = Guid.NewGuid(), Name = "Timuçin", Surname = "KIVANÇ", Department = (int)Departments.IT
            };

            var dto = ClassAdapter <Employee, EmployeeDTO> .Adapt(employee);

            Assert.IsNotNull(dto);

            Assert.IsTrue(dto.Id == employee.Id &&
                          dto.Name == employee.Name &&
                          dto.Department == Departments.IT);
        }
Exemple #17
0
        public void MapEnum()
        {
            TypeAdapterConfig <Employee, EmployeeDTO>
            .NewConfig()
            .MapFrom(dest => dest.Department, src => (Departments)src.Department);

            var employee = new Employee()
            {
                Id = Guid.NewGuid(), Name = "Timuçin", Surname = "KIVANÇ", Department = (int)Departments.IT
            };

            var dto = ClassAdapter <Employee, EmployeeDTO> .Adapt(employee);

            Assert.IsNotNull(dto);

            Assert.IsTrue(dto.Id == employee.Id &&
                          dto.Name == employee.Name &&
                          dto.Department == Departments.IT);
        }
Exemple #18
0
        public void LineTo_WithParameters_WithoutSetColor_ShouldDrawLineFromStartPoint()
        {
            var sw      = new StringWriter();
            var point   = new Point(5, 10);
            var adapter = new ClassAdapter(sw);

            adapter.BeginDraw();
            adapter.LineTo(point.X, point.Y);
            adapter.EndDraw();

            var expected = new StringWriter();

            expected.WriteLine("<draw>");
            expected.WriteLine($"  <line fromX=0 fromY=0 toX={point.X} toY={point.Y}>");
            expected.WriteLine("    <color r=0 g=0 b=0 a=1/>");
            expected.WriteLine("  </line>");
            expected.WriteLine("</draw>");

            Assert.AreEqual(expected.ToString(), sw.ToString());
        }
        public void IgnoreMemberTest()
        {
            var currentDate = DateTime.Now;

            var objA = new ConfigA()
            {
                BirthDate = currentDate,
                Id        = 1,
                Name      = "Timuçin",
                Surname   = "KIVANÇ"
            };

            TypeAdapterConfig <ConfigA, ConfigB> .NewConfig()
            .IgnoreMember(dest => dest.Id);

            var objB = ClassAdapter <ConfigA, ConfigB> .Adapt(objA);

            Assert.IsNotNull(objB);

            Assert.IsTrue(objB.Id == 0 && objB.FullName == null && objB.BirthDate == currentDate);
        }
        public void MapFromTest()
        {
            var currentDate = DateTime.Now;

            var objC = new ConfigC()
            {
                BirthDate = currentDate,
                Id        = 1,
                Name      = "Timuçin",
                Surname   = "KIVANÇ"
            };

            TypeAdapterConfig <ConfigC, ConfigD> .NewConfig()
            //.MapFrom(dest => dest.FullName, (src) => string.Concat(src.Name, " ", src.Surname));
            .MapFrom(dest => dest.FullName, src => string.Concat(src.Name, " ", src.Surname));

            var objD = ClassAdapter <ConfigC, ConfigD> .Adapt(objC);

            Assert.IsNotNull(objD);

            Assert.IsTrue(objD.Id == 1 && objD.FullName == "Timuçin KIVANÇ" && objD.BirthDate == currentDate);
        }
Exemple #21
0
    public void TestClassAdapter()
    {
        ITarget _ITarget = new ClassAdapter();

        _ITarget.Request();
    }
        public void MapCollectionProperty()
        {
            var person = new Person()
            {
                Id      = Guid.NewGuid(),
                Name    = "Timuçin",
                Surname = "KIVANÇ",
                Project = Projects.A,
                X       = new int[] { 1, 2, 3, 4 },
                Y       = new List <int>()
                {
                    5, 6, 7
                },
                Z   = new ArrayList((ICollection)(new List <Guid>()
                {
                    Guid.NewGuid(), Guid.NewGuid()
                })),
                Ids = new List <Guid>()
                {
                    Guid.Empty, Guid.NewGuid()
                },
                CityId    = Guid.NewGuid(),
                Picture   = new byte[] { 0, 1, 2 },
                Countries = new List <string> {
                    "Turkey", "Germany"
                },
                XX = new List <string> {
                    "Nederland", "USA"
                },
                YY = new List <int> {
                    22, 33
                },
                ZZ = new List <int> {
                    44, 55
                },
                RelatedDepartments = new Departments[] { Departments.IT, Departments.Finance }
            };

            var dto = ClassAdapter <Person, PersonDTO> .Adapt(person);

            Assert.IsNotNull(dto);
            Assert.IsTrue(dto.Id == person.Id &&
                          dto.Name == person.Name &&
                          dto.Project == person.Project);

            Assert.IsNotNull(dto.X);
            Assert.IsTrue(dto.X.Count == 4 && dto.X[0] == 1 && dto.X[1] == 2 && dto.X[2] == 3 && dto.X[3] == 4);

            Assert.IsNotNull(dto.Y);
            Assert.IsTrue(dto.Y.Length == 3 && dto.Y[0] == 5 && dto.Y[1] == 6 && dto.Y[2] == 7);

            Assert.IsNotNull(dto.Z);
            Assert.IsTrue(dto.Z.Count == 2 && dto.Z.Contains((Guid)person.Z[0]) && dto.Z.Contains((Guid)person.Z[1]));

            Assert.IsNotNull(dto.Ids);
            Assert.IsTrue(dto.Ids.Count == 2);

            Assert.IsTrue(dto.CityId == person.CityId);

            Assert.IsNotNull(dto.Picture);
            Assert.IsTrue(dto.Picture.Length == 3 && dto.Picture[0] == 0 && dto.Picture[1] == 1 && dto.Picture[2] == 2);

            Assert.IsNotNull(dto.Countries);
            Assert.IsTrue(dto.Countries.Count == 2 && dto.Countries.First() == "Turkey" && dto.Countries.Last() == "Germany");

            Assert.IsNotNull(dto.XX);
            Assert.IsTrue(dto.XX.Count() == 2 && dto.XX.First() == "Nederland" && dto.XX.Last() == "USA");

            Assert.IsNotNull(dto.YY);
            Assert.IsTrue(dto.YY.Count == 2 && dto.YY.First() == 22 && dto.YY.Last() == 33);

            Assert.IsNotNull(dto.ZZ);
            Assert.IsTrue(dto.ZZ.Count == 2 && dto.ZZ.First() == 44 && dto.ZZ.Last() == 55);

            Assert.IsNotNull(dto.RelatedDepartments);
            Assert.IsTrue(dto.RelatedDepartments.Length == 2 && dto.RelatedDepartments[0] == Departments.IT && dto.RelatedDepartments[1] == Departments.Finance);
        }