Пример #1
0
        public void RetrieveAvailableServiceTest()
        {
            Available available = ObjectMother.GetAvailable();

            var repositoryFake = new Mock<IAvailableRepository>();
            repositoryFake.Setup(r => r.Get(1)).Returns(available);

            IAvailableService service = new AvailableService(repositoryFake.Object);

            var availableFake = service.Retrieve(1);

            repositoryFake.Verify(r => r.Get(1));
            Assert.IsNotNull(availableFake);
        }
Пример #2
0
        public void DeleteAvailableServiceTest()
        {
            Available available = null;

            var repositoryFake = new Mock<IAvailableRepository>();
            repositoryFake.Setup(r => r.Delete(1)).Returns(available);

            IAvailableService service = new AvailableService(repositoryFake.Object);

            var availableFake = service.Delete(1);

            repositoryFake.Verify(r => r.Delete(1));
            Assert.IsNull(availableFake);
        }
Пример #3
0
        public void UpdateAvailableServiceValidationAndPersistenceTest()
        {
            Available available = ObjectMother.GetAvailable();

            var repositoryFake = new Mock<IAvailableRepository>();
            repositoryFake.Setup(r => r.Update(available)).Returns(available);

            var availableFake = new Mock<Available>();
            availableFake.As<IObjectValidation>().Setup(b => b.Validate());

            IAvailableService service = new AvailableService(repositoryFake.Object);

            service.Update(availableFake.Object);

            availableFake.As<IObjectValidation>().Verify(b => b.Validate());
            repositoryFake.Verify(r => r.Update(availableFake.Object));
        }
Пример #4
0
        public async Task <bool> CreateAvailableService(AvailableService availableService)
        {
            try
            {
                await _context.AvailableService.AddAsync(new AvailableService()
                {
                    Name   = availableService.Name,
                    Icon   = availableService.Icon,
                    Status = availableService.Status
                });

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Пример #5
0
 public async Task <bool> CreateAvailableService(AvailableService availableService)
 {
     return(await _service.CreateAvailableService(availableService));
 }
Пример #6
0
        private void CheckExportedTypes(string appPath)
        {
            Assembly asm = null;
            try
            {
                foreach (string f in Directory.GetFiles(currentDirectory))
                {
                    if (f.EndsWith(".dll"))
                    {
                        asm = Assembly.LoadFrom(f);
                        try
                        {
                            foreach (var type in asm.GetTypes())
                            {
                                Console.WriteLine(asm.Location);

                                //output.Append(string.Format("Found object {0} in {1}.\r\n", type.Name, asm.CodeBase));
                                if (type.IsClass)
                                {
                                    object instance = asm.CreateInstance(type.FullName);
                                    //output.Append(string.Format("Class {0} is being interrogated.\r\n", type.Name));
                                    Type[] interfaces = type.GetInterfaces();
                                    AvailableService service = new AvailableService();
                                    service.Interfaces = new Dictionary<string, string>();
                                    service.Methods = new StringCollection();
                                    service.FullName = type.FullName;
                                    foreach (var interf in interfaces)
                                    {
                                        //output.Append(string.Format("Implements {0}.\r\n", interf.Name));
                                        foreach (var prop in interf.GetCustomAttributes(true))
                                        {
                                            if (prop.GetType().IsAssignableFrom(typeof(ServiceContractAttribute)))
                                            {
                                                if (!(AvailableContracts.ContainsKey(interf.Name)))
                                                {
                                                    service.Interfaces.Add(interf.Name, interf.Namespace);
                                                    MethodInfo[] modInfo = interf.GetMethods();
                                                    foreach (MethodInfo method in modInfo)
                                                    {
                                                        service.Methods.Add(method.Name);
                                                    }
                                                }
                                                AvailableImplementations.Add(service);
                                            }
                                        }

                                    }
                                }
                            }
                        }
                        catch (Exception ex1)
                        {
                            AssemblyErrors.Add(ex1);
                        }
                    }
                }
                asm = Assembly.LoadFile(appPath);

                foreach (var reference in AppDomain.CurrentDomain.GetAssemblies())
                {
                    ResolvedReferences.Add(reference.FullName);
                }

            }
            catch (Exception ex)
            {
                AssemblyErrors.Add(ex);
            }
        }