示例#1
0
        public void TestAddMacs()
        {
            var testMacs = new AddMacsParams
            {
                Macs = new List <MacAddress>
                {
                    new MacAddress {
                        Value = "AA:AA:AA:AA:AA:A1"
                    },
                    new MacAddress {
                        Value = "BB:BB:BB:BB:BB:B1"
                    },
                    new MacAddress {
                        Value = "BB:BB:BB:BB:BB:B2"
                    },
                    new MacAddress {
                        Value = "CC:CC:CC:CC:CC:C1"
                    },
                    new MacAddress {
                        Value = "CC:CC:CC:CC:CC:C2"
                    }
                }
            };
            var dataService       = new MacAddressService();
            var validationService = new MacAddressValidationService();
            var controller        = new HomeController(dataService, validationService);
            var result            = controller.AddMacs(testMacs);

            Assert.IsTrue(result.IsSuccess);
        }
        public AddMacsResponse AddMacs(AddMacsParams macs)
        {
            var response = new AddMacsResponse {
                IsSuccess = true
            };

            try
            {
                if (!MacAddressValidationService.ValidateMany(macs.Macs))
                {
                    response.Messages  = new string[] { "Validation error" };
                    response.IsSuccess = false;
                }
                else
                {
                    response.AddedCount = MacAddressService.Add(macs.Macs);
                }
            }
            catch (System.Exception ex)
            {
                response.Messages  = new string[] { "Error on AddMacs", ex.Message };
                response.IsSuccess = false;
            }
            return(response);
        }