public async Task PutAsyncTest()
        {
            // Arrange
            var mockCoordinatorRepository = GetDefaultICoordinatorRepositoryInstance();
            var mockIUnitOfWork           = GetDefaultIUnitOfWorkInstance();
            var mockFacultyRepository     = GetDefaultIFacultyRepositoryInstance();
            var mockAccountRepository     = GetDefaultIAccountRepositoryInstance();

            Coordinator coordinator   = new Coordinator();
            int         coordinatorId = 1;

            coordinator.Id        = coordinatorId;
            coordinator.FirstName = "Ricardo";

            Coordinator coordinatorExpected = new Coordinator();

            coordinatorExpected.FirstName = "William";

            mockCoordinatorRepository.Setup(r => r.FindById(coordinatorId))
            .Returns(Task.FromResult <Coordinator>(coordinator));

            var service = new CoordinatorService(mockCoordinatorRepository.Object,
                                                 mockAccountRepository.Object, mockFacultyRepository.Object, mockIUnitOfWork.Object);

            // Act
            CoordinatorResponse result = await service.UpdateASync(coordinatorId, coordinatorExpected);

            // Assert
            Assert.AreEqual(coordinatorExpected.FirstName, result.Resource.FirstName);
        }
        public void PostValidWithEndDateCoordinator()
        {
            var request = new Coordinator {
                Message = "msg", Numbers = new List <string> {
                    "1"
                }, StartTimeUtc = DateTime.Now.AddDays(1), SendAllByUtc = DateTime.Now.AddDays(1), Topic = "topic"
            };

            var bus    = MockRepository.GenerateMock <IBus>();
            var mapper = MockRepository.GenerateMock <ICoordinatorApiModelToMessageMapping>();

            mapper.Expect(m => m.MapToTrickleOverPeriod(Arg <Coordinator> .Is.Equal(request), Arg <Guid> .Is.Anything));
            bus.Expect(b => b.Send(Arg <TrickleSmsOverCalculatedIntervalsBetweenSetDates> .Is.NotNull));

            var service = new CoordinatorService {
                Bus = bus, Mapper = mapper
            };
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.Null);
            Assert.That(response.RequestId, Is.Not.EqualTo(Guid.Empty));

            bus.VerifyAllExpectations();
            mapper.VerifyAllExpectations();
        }
Exemplo n.º 3
0
        public static void SendMetadataRequest(this CoordinatorService glue, PeerHash peer, int piece)
        {
            BencodedValue bencoded = new BencodedValue
            {
                Dictionary = new[]
                {
                    new BencodedEntry
                    {
                        Key = new BencodedValue {
                            Text = new BencodedText("msg_type")
                        },
                        Value = new BencodedValue {
                            Number = new BencodedNumber(0)
                        }
                    },
                    new BencodedEntry
                    {
                        Key = new BencodedValue {
                            Text = new BencodedText("piece")
                        },
                        Value = new BencodedValue {
                            Number = new BencodedNumber(piece)
                        }
                    }
                }
            };

            glue.SendExtension(peer, MetadataPlugin.Name, Bencoder.Encode(bencoded));
        }
        public async Task DeleteAsyncTestHappy()
        {
            // Arrange
            var mockCoordinatorRepository = GetDefaultICoordinatorRepositoryInstance();
            var mockIUnitOfWork           = GetDefaultIUnitOfWorkInstance();
            var mockFacultyRepository     = GetDefaultIFacultyRepositoryInstance();
            var mockAccountRepository     = GetDefaultIAccountRepositoryInstance();

            Coordinator coordinator   = new Coordinator();
            int         coordinatorId = 1;

            coordinator.Id = coordinatorId;

            mockCoordinatorRepository.Setup(r => r.FindById(coordinatorId))
            .Returns(Task.FromResult <Coordinator>(coordinator));

            var service = new CoordinatorService(mockCoordinatorRepository.Object,
                                                 mockAccountRepository.Object, mockFacultyRepository.Object, mockIUnitOfWork.Object);

            // Act
            CoordinatorResponse result = await service.DeleteAsync(coordinatorId);

            // Assert
            Assert.AreEqual(coordinator, result.Resource);
        }
        public void PostInvalidMessageExceedsLength()
        {
            var request = new Coordinator { Numbers = new List<string> { "1" }, StartTimeUtc = DateTime.Now.AddMinutes(1), SendAllByUtc = DateTime.Now.AddDays(1), Message = "sdf;lkj asd;vlkja sdvklja v;lka jsdvlka jsdvalsjk sdf;lkj asd;vlkja sdvklja v;lka jsdvlka jsdvalsjk sdf;lkj asd;vlkja sdvklja v;lka jsdvlka jsdvalsjk sdf;lkj asd;vlkja sdvklja v;lka jsdvlka jsdvalsjk sdf;lkj asd;vlkja sdvklja v;lka jsdvlka jsdvalsjk" };
            var service = new CoordinatorService();
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("InvalidMessage"));
            Assert.That(response.ResponseStatus.Errors[0].Message, Is.EqualTo("Sms exceeds 160 character length"));
        }
        public void PostInvalidBothTimeSeparatorAndSendAllAtOnceSet()
        {
            var request = new Coordinator { Message = "msg", Numbers = new List<string> { "1" }, StartTimeUtc = DateTime.Now.AddMinutes(3), SendAllAtOnce = true, TimeSeparator = new TimeSpan(300)};
            var service = new CoordinatorService();
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("InvalidMessage"));
            Assert.That(response.ResponseStatus.Errors[0].Message, Is.EqualTo("Message must contain either Time Separator OR DateTime to send all messages by."));
        }
Exemplo n.º 7
0
        public bool Init()
        {
            masterService      = new MasterService("tcp://localhost:8080/Master");
            coordinatorService = new CoordinatorService(masterService);
            //timestampService = new TimestampService();
            debugService = new DebugService(masterService);

            return(true);
        }
        public void PostInvalidNoNumbers()
        {
            var request = new Coordinator {
                Message = "msg", StartTimeUtc = DateTime.Now, SendAllByUtc = DateTime.Now.AddDays(1)
            };
            var service  = new CoordinatorService();
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("InvalidMessage"));
            Assert.That(response.ResponseStatus.Errors[0].Message, Is.EqualTo("List of numbers required"));
        }
        public void PostInvalidNoStartTime()
        {
            var request = new Coordinator {
                Message = "msg", Numbers = new List <string> {
                    "1"
                }, SendAllByUtc = DateTime.Now.AddDays(1)
            };
            var service  = new CoordinatorService();
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("InvalidMessage"));
            Assert.That(response.ResponseStatus.Errors[0].Message, Is.EqualTo("Start time must be set"));
        }
        public void PostInvalidMessageExceedsLength()
        {
            var request = new Coordinator {
                Numbers = new List <string> {
                    "1"
                }, StartTimeUtc = DateTime.Now.AddMinutes(1), SendAllByUtc = DateTime.Now.AddDays(1), Message = "sdf;lkj asd;vlkja sdvklja v;lka jsdvlka jsdvalsjk sdf;lkj asd;vlkja sdvklja v;lka jsdvlka jsdvalsjk sdf;lkj asd;vlkja sdvklja v;lka jsdvlka jsdvalsjk sdf;lkj asd;vlkja sdvklja v;lka jsdvlka jsdvalsjk sdf;lkj asd;vlkja sdvklja v;lka jsdvlka jsdvalsjk"
            };
            var service  = new CoordinatorService();
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("InvalidMessage"));
            Assert.That(response.ResponseStatus.Errors[0].Message, Is.EqualTo("Sms exceeds 160 character length"));
        }
        public void PostInvalidNoMessage()
        {
            var request = new Coordinator {
                Numbers = new List <string> {
                    "1"
                }, StartTimeUtc = DateTime.Now.AddMinutes(1), SendAllByUtc = DateTime.Now.AddDays(1)
            };
            var service  = new CoordinatorService();
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("InvalidMessage"));
            Assert.That(response.ResponseStatus.Errors[0].Message, Is.EqualTo("Sms Message Required"));
        }
        public void PostInvalidBothSendAllAtOnceAndSendBySet()
        {
            var request = new Coordinator {
                Message = "msg", Numbers = new List <string> {
                    "1"
                }, StartTimeUtc = DateTime.Now.AddMinutes(3), SendAllByUtc = DateTime.Now.AddMinutes(33), SendAllAtOnce = true
            };
            var service  = new CoordinatorService();
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("InvalidMessage"));
            Assert.That(response.ResponseStatus.Errors[0].Message, Is.EqualTo("Message must contain either Time Separator OR DateTime to send all messages by."));
        }
        public void GetNotFound()
        {
            var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>();
            ravenDocStore.Expect(r => r.GetStore()).Return(base.DocumentStore);
            var service = new CoordinatorService { RavenDocStore = ravenDocStore };

            var notFoundRequestId = Guid.NewGuid();
            var request = new Coordinator { RequestId = notFoundRequestId };
            var response = service.OnGet(request) as CoordinatorResponse;

            Assert.That(response.RequestId, Is.EqualTo(notFoundRequestId));
            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("NotFound"));
        }
Exemplo n.º 14
0
 public CommandModule(
     IServiceProvider services,
     DiscordSocketClient client,
     CommandService commands,
     RiotService riotService,
     RoleService roleService,
     CoordinatorService coordinatorService)
 {
     this.services           = services;
     this.client             = client;
     this.commands           = commands;
     this.riotService        = riotService;
     this.roleService        = roleService;
     this.coordinatorService = coordinatorService;
 }
Exemplo n.º 15
0
 public static bool Init()
 {
     try
     {
         masterService      = new MasterService("tcp://localhost:8080/Master");
         coordinatorService = new CoordinatorService(masterService);
         //timestampService = new TimestampService();
         debugService = new DebugService(masterService);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
     return(true);
 }
        public void GetFound()
        {
            var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>();
            ravenDocStore.Expect(r => r.GetStore()).Return(base.DocumentStore);
            var service = new CoordinatorService {RavenDocStore = ravenDocStore};

            var request = new Coordinator { RequestId = _coordinatorId };
            var response = service.OnGet(request) as CoordinatorResponse;

            Assert.That(response.RequestId, Is.EqualTo(_coordinatorId));
            Assert.That(response.Messages.Count, Is.EqualTo(2));
            Assert.That(response.Messages[0].Number, Is.EqualTo("12313"));
            Assert.That(response.Messages[0].Status, Is.EqualTo(MessageStatusTracking.CompletedSuccess));
            Assert.That(response.Messages[1].Number, Is.EqualTo("434039"));
            Assert.That(response.Messages[1].Status, Is.EqualTo(MessageStatusTracking.Scheduled));

            ravenDocStore.VerifyAllExpectations();
        }
        public void GetNotFound()
        {
            var ravenDocStore = MockRepository.GenerateMock <IRavenDocStore>();

            ravenDocStore.Expect(r => r.GetStore()).Return(base.DocumentStore);
            var service = new CoordinatorService {
                RavenDocStore = ravenDocStore
            };

            var notFoundRequestId = Guid.NewGuid();
            var request           = new Coordinator {
                RequestId = notFoundRequestId
            };
            var response = service.OnGet(request) as CoordinatorResponse;

            Assert.That(response.RequestId, Is.EqualTo(notFoundRequestId));
            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("NotFound"));
        }
Exemplo n.º 18
0
        public static void SendPeers(this CoordinatorService glue, PeerHash peer, params NetworkAddress[] remotes)
        {
            BencodedValue bencoded = new BencodedValue
            {
                Dictionary = new[]
                {
                    new BencodedEntry
                    {
                        Key = new BencodedValue {
                            Text = new BencodedText("added")
                        },
                        Value = new BencodedValue {
                            Data = ToData(remotes)
                        }
                    }
                }
            };

            glue.SendExtension(peer, PeersPlugin.Name, Bencoder.Encode(bencoded));
        }
Exemplo n.º 19
0
        public static void SendMetadataPiece(this CoordinatorService glue, PeerHash peer, int piece, int total, byte[] data)
        {
            BencodedValue bencoded = new BencodedValue
            {
                Dictionary = new[]
                {
                    new BencodedEntry
                    {
                        Key = new BencodedValue {
                            Text = new BencodedText("msg_type")
                        },
                        Value = new BencodedValue {
                            Number = new BencodedNumber(1)
                        }
                    },
                    new BencodedEntry
                    {
                        Key = new BencodedValue {
                            Text = new BencodedText("piece")
                        },
                        Value = new BencodedValue {
                            Number = new BencodedNumber(piece)
                        }
                    },
                    new BencodedEntry
                    {
                        Key = new BencodedValue {
                            Text = new BencodedText("total_size")
                        },
                        Value = new BencodedValue {
                            Number = new BencodedNumber(total)
                        }
                    }
                }
            };

            byte[] payload = Bencoder.Encode(bencoded);

            Bytes.Append(ref payload, data);
            glue.SendExtension(peer, MetadataPlugin.Name, payload);
        }
Exemplo n.º 20
0
        public async Task GetAsyncTestUnhappy()
        {
            // Arrange
            var mockCoordinatorRepository = GetDefaultICoordinatorRepositoryInstance();
            var mockIUnitOfWork           = GetDefaultIUnitOfWorkInstance();
            var mockFacultyRepository     = GetDefaultIFacultyRepositoryInstance();
            var mockAccountRepository     = GetDefaultIAccountRepositoryInstance();
            int coordinatorId             = 1;


            var service = new CoordinatorService(mockCoordinatorRepository.Object,
                                                 mockAccountRepository.Object, mockFacultyRepository.Object, mockIUnitOfWork.Object);

            // Act
            CoordinatorResponse result = await service.GetByIdAsync(coordinatorId);

            var message = result.Message;

            // Assert
            message.Should().Be("Coordinator not found");
        }
Exemplo n.º 21
0
        public async Task SaveAsyncWhenCoordinatorsReturnsSuccess()
        {
            //
            var mockCoordinatorRepository = GetDefaultICoordinatorRepositoryInstance();
            var mockIUnitOfWork           = GetDefaultIUnitOfWorkInstance();
            var mockFacultyRepository     = GetDefaultIFacultyRepositoryInstance();
            var mockAccountRepository     = GetDefaultIAccountRepositoryInstance();

            Coordinator coordinator = new Coordinator();

            mockCoordinatorRepository.Setup(r => r.AddAsync(coordinator))
            .Returns(Task.FromResult <Coordinator>(coordinator));
            var service = new CoordinatorService(mockCoordinatorRepository.Object,
                                                 mockAccountRepository.Object, mockFacultyRepository.Object, mockIUnitOfWork.Object);
            //
            CoordinatorResponse result = await service.SaveAsync(coordinator);

            var message = result.Message;

            //
            message.Should().Be("");
        }
Exemplo n.º 22
0
        public void HandlePeerConnected(CoordinatorService service, ExtensionListReceived data)
        {
            if (data.Extensions.Contains(Name) == false)
            {
                return;
            }

            service.ForEachPeer((peer, remote, direction) =>
            {
                if (peer.Equals(data.Peer))
                {
                    return;
                }

                if (direction == NetworkDirection.Incoming)
                {
                    return;
                }

                service.SendPeers(data.Peer, remote);
            });
        }
        public void GetFound()
        {
            var ravenDocStore = MockRepository.GenerateMock <IRavenDocStore>();

            ravenDocStore.Expect(r => r.GetStore()).Return(base.DocumentStore);
            var service = new CoordinatorService {
                RavenDocStore = ravenDocStore
            };

            var request = new Coordinator {
                RequestId = _coordinatorId
            };
            var response = service.OnGet(request) as CoordinatorResponse;

            Assert.That(response.RequestId, Is.EqualTo(_coordinatorId));
            Assert.That(response.Messages.Count, Is.EqualTo(2));
            Assert.That(response.Messages[0].Number, Is.EqualTo("12313"));
            Assert.That(response.Messages[0].Status, Is.EqualTo(MessageStatusTracking.CompletedSuccess));
            Assert.That(response.Messages[1].Number, Is.EqualTo("434039"));
            Assert.That(response.Messages[1].Status, Is.EqualTo(MessageStatusTracking.Scheduled));

            ravenDocStore.VerifyAllExpectations();
        }
        public void PostInvalidNoMessage()
        {
            var request = new Coordinator { Numbers = new List<string> { "1" }, StartTimeUtc = DateTime.Now.AddMinutes(1), SendAllByUtc = DateTime.Now.AddDays(1) };
            var service = new CoordinatorService();
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("InvalidMessage"));
            Assert.That(response.ResponseStatus.Errors[0].Message, Is.EqualTo("Sms Message Required"));
        }
Exemplo n.º 25
0
 public MetashareBuilder WithGlue(CoordinatorService glue)
 {
     dependencies.Glue = glue;
     return(this);
 }
Exemplo n.º 26
0
 public MetadataSession(CoordinatorService coordinator, MetadataPlugin plugin)
 {
     this.coordinator = coordinator;
     this.plugin      = plugin;
 }
        public void PostValidTimeSeparatedCoordinator()
        {
            var request = new Coordinator { Message = "msg", Numbers = new List<string> { "1" }, StartTimeUtc = DateTime.Now.AddDays(1), TimeSeparator = new TimeSpan(0,0,3)};
            var bus = MockRepository.GenerateMock<IBus>();
            var mapper = MockRepository.GenerateMock<ICoordinatorApiModelToMessageMapping>();

            mapper.Expect(m => m.MapToTrickleSpacedByPeriod(Arg<Coordinator>.Is.Equal(request), Arg<Guid>.Is.Anything));
            bus.Expect(b => b.Send(Arg<TrickleSmsWithDefinedTimeBetweenEachMessage>.Is.NotNull));

            var service = new CoordinatorService { Bus = bus, Mapper = mapper };
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.Null);
            Assert.That(response.RequestId, Is.Not.EqualTo(Guid.Empty));

            bus.VerifyAllExpectations();
            mapper.VerifyAllExpectations();
        }
Exemplo n.º 28
0
 public DataShareToGlueAdapter(CoordinatorService service)
 {
     this.service = service;
 }
        public void PostValidWithEndDateCoordinator()
        {
            var request = new Coordinator { Message = "msg", Numbers = new List<string> { "1" }, StartTimeUtc = DateTime.Now.AddDays(1), SendAllByUtc = DateTime.Now.AddDays(1), Topic = "topic"};

            var bus = MockRepository.GenerateMock<IBus>();
            var mapper = MockRepository.GenerateMock<ICoordinatorApiModelToMessageMapping>();

            mapper.Expect(m => m.MapToTrickleOverPeriod(Arg<Coordinator>.Is.Equal(request), Arg<Guid>.Is.Anything));
            bus.Expect(b => b.Send(Arg<TrickleSmsOverCalculatedIntervalsBetweenSetDates>.Is.NotNull));

            var service = new CoordinatorService { Bus = bus, Mapper = mapper };
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.Null);
            Assert.That(response.RequestId, Is.Not.EqualTo(Guid.Empty));

            bus.VerifyAllExpectations();
            mapper.VerifyAllExpectations();
        }
        public void PostNoTopic()
        {
            var request = new Coordinator { Message = "msg", Numbers = new List<string> { "1" }, StartTimeUtc = DateTime.Now.AddHours(1), SendAllByUtc = DateTime.Now.AddDays(1), Topic = string.Empty};
            var service = new CoordinatorService();
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("InvalidMessage"));
            Assert.That(response.ResponseStatus.Errors[0].Message, Is.EqualTo("Topic must be set"));
        }
Exemplo n.º 31
0
 public static DataShareToGlue AsDataShare(this CoordinatorService service)
 {
     return(new DataShareToGlueAdapter(service));
 }
Exemplo n.º 32
0
 public PeersSession(CoordinatorService coordinator, PeersPlugin plugin)
 {
     this.coordinator = coordinator;
     this.plugin      = plugin;
 }
Exemplo n.º 33
0
 public CoordinatorInstance(CoordinatorService service)
 {
     this.service = service;
 }
Exemplo n.º 34
0
 public CoordinatorController(ICoordinatorRepository CoordinatoRepository)
 {
     _CoordinatorService = new CoordinatorService(CoordinatoRepository);
 }
Exemplo n.º 35
0
 public CoordinatorSession(CoordinatorService coordinator)
 {
     this.coordinator = coordinator;
 }
Exemplo n.º 36
0
 public MetaGetToGlueAdapter(CoordinatorService service)
 {
     this.service = service;
 }
        public void PostInvalidNoNumbers()
        {
            var request = new Coordinator { Message = "msg", StartTimeUtc = DateTime.Now, SendAllByUtc = DateTime.Now.AddDays(1) };
            var service = new CoordinatorService();
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("InvalidMessage"));
            Assert.That(response.ResponseStatus.Errors[0].Message, Is.EqualTo("List of numbers required"));
        }
Exemplo n.º 38
0
 public static MetagetGlue AsMetaGet(this CoordinatorService service)
 {
     return(new MetaGetToGlueAdapter(service));
 }
        public void PostInvalidStartTimeInPast()
        {
            var request = new Coordinator { Message = "msg", Numbers = new List<string> { "1" }, StartTimeUtc = DateTime.Now.AddDays(-1), SendAllByUtc = DateTime.Now.AddDays(1) };
            var service = new CoordinatorService();
            var response = service.OnPost(request) as CoordinatorResponse;

            Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo("InvalidMessage"));
            Assert.That(response.ResponseStatus.Errors[0].Message, Is.EqualTo("Start time must not be in the past"));
        }