Ejemplo n.º 1
0
        public void Given_An_AttributeTypeId_When_Queried_It_Should_Filter_Records_And_Return_Records()
        {
            int?attributeTypeId = 123456;
            var response        = GetMpAttributeResponse();

            _ministryPlatformRestService.Setup(
                mocked =>
                mocked.Search <MpAttribute>(
                    It.Is <string>(
                        m =>
                        m.Equals(
                            $"Attributes.Attribute_Type_ID = {attributeTypeId}  AND (Attributes.Start_Date Is Null OR Attributes.Start_Date <= GetDate()) AND (Attributes.End_Date Is Null OR Attributes.End_Date >= GetDate())")),
                    It.Is <string>(m => m.Equals("Attribute_ID, Attribute_Name, Attributes.Description, Attribute_Category_ID_Table.Attribute_Category, Attributes.Attribute_Category_ID, Attribute_Category_ID_Table.Description as Attribute_Category_Description, Attributes.Sort_Order, Attribute_Type_ID_Table.Attribute_Type_ID, Attribute_Type_ID_Table.Attribute_Type, Attribute_Type_ID_Table.Prevent_Multiple_Selection, Start_Date, End_Date")),
                    It.IsAny <string>(),
                    It.IsAny <bool>())).Returns(response);

            var attributes = _fixture.GetAttributes(attributeTypeId);

            _ministryPlatformRestService.VerifyAll();

            Assert.IsNotNull(attributes);
            Assert.AreEqual(3, attributes.Count());

            var attribute = attributes[0];

            Assert.AreEqual(1, attribute.AttributeId);
            Assert.AreEqual("Attribute #1", attribute.Name);
            Assert.AreEqual(2, attribute.CategoryId);
            Assert.AreEqual("Category #1", attribute.Category);
            Assert.AreEqual(3, attribute.AttributeTypeId);
            Assert.AreEqual("AttributeType #1", attribute.AttributeTypeName);

            attribute = attributes[1];
            Assert.AreEqual(4, attribute.AttributeId);
            Assert.AreEqual("Attribute #2", attribute.Name);
            Assert.AreEqual(5, attribute.CategoryId);
            Assert.AreEqual("Category #2", attribute.Category);
            Assert.AreEqual(6, attribute.AttributeTypeId);
            Assert.AreEqual("AttributeType #1", attribute.AttributeTypeName);

            attribute = attributes[2];
            Assert.AreEqual(7, attribute.AttributeId);
            Assert.AreEqual("Attribute #3", attribute.Name);
            Assert.AreEqual(null, attribute.CategoryId);
            Assert.AreEqual(null, attribute.Category);
            Assert.AreEqual(9, attribute.AttributeTypeId);
            Assert.AreEqual("AttributeType #2", attribute.AttributeTypeName);
        }