public async Task AllConfirmedAsync_ShouldReturnsCorrectCountOfConfirmedSubscribers()
        {
            await this.dbContext.Subscribers.AddRangeAsync(new List <Subscriber>
            {
                new Subscriber {
                    IsConfirmed = true
                },
                new Subscriber {
                    IsConfirmed = false
                },
                new Subscriber {
                    IsConfirmed = true
                },
                new Subscriber {
                    IsConfirmed = true
                },
                new Subscriber {
                    IsConfirmed = false
                },
            });

            await this.dbContext.SaveChangesAsync();

            var subscriberService = new SubscriberService(this.dbContext);

            var result = await subscriberService.AllConfirmedAsync <FakeSubscriber>();

            var expectedCount = 3;
            var actualCount   = result.Count();

            Assert.Equal(expectedCount, actualCount);
        }
Esempio n. 2
0
        public void TestUnsubscribe()
        {
            const string email = "*****@*****.**";
            var          token = SubscriberService.CalculateToken(email);

            Assert.IsTrue(SubscriberService.VerifyToken(email, token));
        }
Esempio n. 3
0
        public async Task HandleMemberSubscriptionAsync_UnsubscribedSubscriber_ShouldBeResubscribedWithStatusPending()
        {
            //arrange
            var nullLogger             = new NullLogger <SubscriberService>();
            var fakeRepository         = new FakeMailchimpRepository();
            var subscriberService      = new SubscriberService(nullLogger, fakeRepository);
            var unsubscribedSubscriber = new NewSubscriberDto()
            {
                Email  = "*****@*****.**",
                Name   = "Unsubscribed",
                Source = "UnitTest"
            };

            //assume
            var assumedMember = await fakeRepository.GetMemberAsync(unsubscribedSubscriber.Email);

            Assume.That(
                assumedMember?.Status ==
                "unsubscribed", "Missing unsubscribed member in the collection");

            //act
            await subscriberService.HandleMemberSubscriptionAsync(unsubscribedSubscriber);

            MemberDto receivedMember = await fakeRepository.GetMemberAsync(unsubscribedSubscriber.Email);

            //assert
            Assert.Equal(unsubscribedSubscriber.Email, receivedMember.EmailAddress);
            Assert.Equal("pending", receivedMember.Status);
        }
Esempio n. 4
0
        public void GetByUserTest()
        {
            var id   = new Guid();
            var list = new List <Subscriber>()
            {
                new Subscriber()
                {
                    Id            = new Guid(),
                    UserProfileId = id
                },
                new Subscriber()
                {
                    Id            = new Guid(),
                    UserProfileId = new Guid()
                }
            };
            var unit = new MockUnitOfWork();

            unit.MockRepository();
            unit.MockGetAllForRep(list);
            var service = new SubscriberService(unit.Object);

            var res = service.GetByUser(id).GetAwaiter().GetResult();

            Assert.NotNull(res);
            Assert.NotEmpty(res);
            Assert.Equal(id, res.First().UserProfileId);
            Assert.IsAssignableFrom <IEnumerable <Subscriber> >(res);
        }
        public async Task GetAsync_Projection_ShouldGetCorrectSubscriber_WhenCategoryExists()
        {
            var wantedSubscriberId = Guid.NewGuid().ToString();
            var wantedSubscriberConfirmationCode = Guid.NewGuid().ToString();

            await this.dbContext.Subscribers.AddRangeAsync(new List <Subscriber>()
            {
                new Subscriber {
                    Id = "1", ConfirmationCode = "1"
                },
                new Subscriber {
                    Id = wantedSubscriberId, ConfirmationCode = wantedSubscriberConfirmationCode
                },
                new Subscriber {
                    Id = "3", ConfirmationCode = "3"
                },
            });

            await this.dbContext.SaveChangesAsync();

            var subscriberService = new SubscriberService(this.dbContext);

            var expectedSubscriberId = wantedSubscriberId;
            var subscriber           = await subscriberService.GetAsync <FakeSubscriber>(wantedSubscriberId, wantedSubscriberConfirmationCode);

            Assert.Equal(expectedSubscriberId, subscriber.Id);
        }
        public async Task GetAsync_ShouldGetCorrectSubscriber_WhenEmailExists()
        {
            var wantedSubscriberId    = Guid.NewGuid().ToString();
            var wantedSubscriberEmail = Guid.NewGuid().ToString();

            await this.dbContext.Subscribers.AddRangeAsync(new List <Subscriber>()
            {
                new Subscriber {
                    Id = "1", Email = "*****@*****.**"
                },
                new Subscriber {
                    Id = wantedSubscriberId, Email = wantedSubscriberEmail
                },
                new Subscriber {
                    Id = "3", Email = "*****@*****.**"
                },
            });

            await this.dbContext.SaveChangesAsync();

            var subscriberService = new SubscriberService(this.dbContext);

            var expectedSubscriberId = wantedSubscriberId;
            var subscriber           = await subscriberService.GetAsync(wantedSubscriberEmail);

            Assert.Equal(expectedSubscriberId, subscriber.Id);
        }
        public async Task GetAsync_Projection_ShouldThrowInvalidSubscriberException_WhenSubscriberNotExists()
        {
            var correctConfirmationCode = Guid.NewGuid().ToString();

            await this.dbContext.Subscribers.AddRangeAsync(new List <Subscriber>()
            {
                new Subscriber {
                    Id = "1", ConfirmationCode = "1"
                },
                new Subscriber {
                    Id = "2", ConfirmationCode = correctConfirmationCode
                },
                new Subscriber {
                    Id = "3", ConfirmationCode = "3"
                },
            });

            await this.dbContext.SaveChangesAsync();

            var subscriberService = new SubscriberService(this.dbContext);

            var incorrectId = Guid.NewGuid().ToString();

            Assert.Throws <InvalidSubscriberException>(() =>
                                                       subscriberService.GetAsync <FakeSubscriber>(incorrectId, correctConfirmationCode).GetAwaiter().GetResult());
        }
        public async Task ExistsAsync_ShouldReturnsTrue_WhenSubscriberEmailExists()
        {
            var existingEmail = "*****@*****.**";

            await this.dbContext.Subscribers.AddRangeAsync(new List <Subscriber>
            {
                new Subscriber {
                    Email = "*****@*****.**"
                },
                new Subscriber {
                    Email = "*****@*****.**"
                },
                new Subscriber {
                    Email = existingEmail
                },
                new Subscriber {
                    Email = "*****@*****.**"
                },
                new Subscriber {
                    Email = "*****@*****.**"
                },
            });

            await this.dbContext.SaveChangesAsync();

            var subscriberService = new SubscriberService(this.dbContext);

            var result = await subscriberService.ExistsAsync(existingEmail);

            Assert.True(result);
        }
        public async Task ExistsAsync_ShouldReturnsFalse_WhenSubscriberEmailNotExists()
        {
            await this.dbContext.Subscribers.AddRangeAsync(new List <Subscriber>
            {
                new Subscriber {
                    Email = "*****@*****.**"
                },
                new Subscriber {
                    Email = "*****@*****.**"
                },
                new Subscriber {
                    Email = "*****@*****.**"
                },
                new Subscriber {
                    Email = "*****@*****.**"
                },
                new Subscriber {
                    Email = "*****@*****.**"
                },
            });

            await this.dbContext.SaveChangesAsync();

            var subscriberService = new SubscriberService(this.dbContext);

            var notExistingEmail = "*****@*****.**";
            var result           = await subscriberService.ExistsAsync(notExistingEmail);

            Assert.False(result);
        }
Esempio n. 10
0
        public async Task HandleMemberSubscriptionAsync_AlreadySubscribed_ShouldBeNotChanged()
        {
            //arrange
            var nullLogger           = new NullLogger <SubscriberService>();
            var fakeRepository       = new FakeMailchimpRepository();
            var subscriberService    = new SubscriberService(nullLogger, fakeRepository);
            var subscribedSubscriber = new NewSubscriberDto()
            {
                Email  = "*****@*****.**",
                Name   = "Subscribed",
                Source = "UnitTest"
            };

            //assume
            var assumedMember = await fakeRepository.GetMemberAsync(subscribedSubscriber.Email);

            Assume.That(
                assumedMember?.Status ==
                "subscribed", "Missing subscribed member in the collection");

            //act
            await subscriberService.HandleMemberSubscriptionAsync(subscribedSubscriber);

            MemberDto receivedMember = await fakeRepository.GetMemberAsync(subscribedSubscriber.Email);

            var memberChanges = fakeRepository.Members["*****@*****.**"];

            //assert
            Assert.Single(memberChanges);
            Assert.Equal(subscribedSubscriber.Email, receivedMember.EmailAddress);
            Assert.Equal("subscribed", receivedMember.Status);
        }
Esempio n. 11
0
        public async Task HandleMemberSubscriptionAsync_Pending_ShouldBeChangedByEmailsServiceToUnsubscribedThanPending()
        {
            //arrange
            var nullLogger        = new NullLogger <SubscriberService>();
            var fakeRepository    = new FakeMailchimpRepository();
            var subscriberService = new SubscriberService(nullLogger, fakeRepository);
            var newSubscriber     = new NewSubscriberDto()
            {
                Email  = "*****@*****.**",
                Name   = "Marek",
                Source = "UnitTest"
            };

            //act
            await subscriberService.HandleMemberSubscriptionAsync(newSubscriber);

            MemberDto receivedMember = await fakeRepository.GetMemberAsync(newSubscriber.Email);

            var memberHistory = fakeRepository.Members["*****@*****.**"];

            //assert
            Assert.Equal(3, memberHistory.Count);
            Assert.Equal(newSubscriber.Email, receivedMember.EmailAddress);
            Assert.Equal("unsubscribed", memberHistory.ElementAt(1).Status);
            Assert.Equal("pending", receivedMember.Status);
        }
Esempio n. 12
0
        /// <summary>
        /// This method Send Message
        /// </summary>
        public void SendMessage(bool isPrivate = false, SubscriberCallback subscriber = null)
        {
            // Create a new instance of a 'SubscriberMessage' object.
            SubscriberMessage message = null;

            // Create a new instance of a 'SubscriberMessage' object.
            message          = new SubscriberMessage();
            message.Text     = MessageText;
            message.FromId   = Id;
            message.FromName = SubscriberName;
            message.SentTime = DateTime.Now;

            // Set the Time
            message.Sent = DateTime.Now;

            // Set the
            message.BubbleColor = (BubbleColorEnum)Shuffler.PullNextItem();

            try
            {
                // If the MessageText string exists
                if (TextHelper.Exists(MessageText))
                {
                    // if this is a private message
                    if ((isPrivate) && (NullHelper.Exists(subscriber)) && (subscriber.HasCallback))
                    {
                        // Set the ToName
                        message.ToName = subscriber.Name;
                        message.ToId   = subscriber.Id;

                        // This is a private message
                        message.IsPrivate = true;

                        //  Send this message to all clients
                        SubscriberService.SendPrivateMessage(subscriber, message);
                    }
                    else
                    {
                        // Set the ToName
                        message.ToName = "Room";
                        message.ToId   = Guid.Empty;

                        //  Send this message to all clients
                        SubscriberService.BroadcastMessage(message);
                    }

                    // Erase the Text
                    MessageText = "";

                    // Deliver the message to this client, without being Broadcast
                    Listen(message);
                }
            }
            catch (Exception error)
            {
                // for debugging only
                DebugHelper.WriteDebugError("BroadCastMessage", "Chat.razor.cs", error);
            }
        }
Esempio n. 13
0
 public override List <Subscriber> Subscribers(SubscriberService subscriberService)
 {
     return(new List <Subscriber> {
         new Subscriber {
             Name = _email
         }
     });
 }
        public void AddAsync_WithEmailAlreadyExist_ThrowException()
        {
            SubscriberModel   subscriberModel   = new SubscriberModel();
            var               mockUoW           = new Mock <IUnitOfWork>();
            SubscriberService subscriberService = new SubscriberService(mockUoW.Object);

            subscriberService.AddAsync
        }
Esempio n. 15
0
        public WcfHost()
        {
            instance = new SubscriberService();
            host     = new ServiceHost(instance, new Uri("net.tcp://localhost:8600"));
            Binding binding = new NetTcpBinding(SecurityMode.Transport);

            host.AddServiceEndpoint(typeof(ISubscriberService).FullName, binding, "net.tcp://localhost:8600/Test");
            host.Open();
        }
        public async void GetCardId_CardExists_returnSuscriberWithThisCardId()
        {
            var subscriberService = new SubscriberService(
                new SubscriberRepository(
                    new WeightWatchersContext()));
            CardModel result = await subscriberService.GetByIdAsync(1);

            Assert.Equals(1, result.id);
        }
Esempio n. 17
0
        public WcfHost()
        {
            instance = new SubscriberService();
            host = new ServiceHost(instance, new Uri("net.tcp://localhost:8600"));
            Binding binding = new NetTcpBinding(SecurityMode.Transport);

            host.AddServiceEndpoint(typeof(ISubscriberService).FullName, binding, "net.tcp://localhost:8600/Test");
            host.Open();
        }
Esempio n. 18
0
 /// <summary>
 /// This method Dispose
 /// </summary>
 public void Dispose()
 {
     // If the SubscriberService object exists
     if (NullHelper.Exists(SubscriberService))
     {
         // Unsubscribe from the service
         SubscriberService.Unsubscribe(Id);
     }
 }
        public async Task CreateAsync_ShouldAddNewSubscriber_WithNotConfirmedEmail()
        {
            var subscriberService = new SubscriberService(this.dbContext);

            var newSubscriberEmail = "*****@*****.**";
            var newSubscriber      = await subscriberService.CreateAsync(newSubscriberEmail);

            var newSubscriberFromDb = await this.dbContext.Subscribers.FindAsync(newSubscriber.Id);

            Assert.False(newSubscriberFromDb.IsConfirmed);
        }
        public async Task CreateAsync_ShouldGenerateConfirmationCodeToNewSubscriber()
        {
            var subscriberService = new SubscriberService(this.dbContext);

            var newSubscriberEmail = "*****@*****.**";
            var newSubscriber      = await subscriberService.CreateAsync(newSubscriberEmail);

            var newSubscriberFromDb = await this.dbContext.Subscribers.FindAsync(newSubscriber.Id);

            Assert.NotNull(newSubscriberFromDb.ConfirmationCode);
        }
        public async Task CreateAsync_ShouldAddNewSubscriberToDb()
        {
            var subscriberService = new SubscriberService(this.dbContext);

            var newSubscriberEmail = "*****@*****.**";
            await subscriberService.CreateAsync(newSubscriberEmail);

            const int expected = 1;
            var       actual   = this.dbContext.Subscribers.Count();

            Assert.Equal(expected, actual);
        }
Esempio n. 22
0
        /// <summary>
        /// This method is used to send a Private message to a user
        /// </summary>
        /// <param name="args"></param>
        /// <param name="toId"></param>
        private void SendPrivateMessageClicked(EventArgs args, Guid toId)
        {
            // Attempt to find the subscriber
            SubscriberCallback subscriber = SubscriberService.FindSubscriber(toId);

            // If the subscriber object exists
            if (NullHelper.Exists(subscriber))
            {
                // Send a message
                SendMessage(true, subscriber);
            }
        }
Esempio n. 23
0
        public void Initialize()
        {
            _gateFactory       = A.Fake <IGateFactory>();
            _fallbackService   = A.Fake <IFallbackService>();
            _httpClientFactory = A.Fake <IHttpClientFactory>();
            var logger = A.Fake <ILogger <SubscriberService> >();

            _toTest = new SubscriberService(_gateFactory, new List <IFallbackService>
            {
                _fallbackService
            }, _httpClientFactory, logger);
        }
        public void Add_Subscriber_To_Db()
        {
            var mockDbSet   = new Mock <DbSet <Subscriber> >();
            var mockContext = new Mock <RentalContext>();

            mockContext.Setup(r => r.Subscribers).Returns(mockDbSet.Object);
            var service = new SubscriberService(mockContext.Object);

            service.Add(new Subscriber());

            mockContext.Verify(a => a.Add(It.IsAny <Subscriber>()), Times.Once);
            mockContext.Verify(s => s.SaveChanges(), Times.Once);
        }
Esempio n. 25
0
        public async void LoginAsync_EmailExist_GotMinus1()
        {
            var optionsBuilder = new DbContextOptionsBuilder <WeightWatchersContext>()
                                 .UseSqlServer("Server = C1; Database = WeightWatchersDB ;Trusted_Connection=True; ").Options;
            WeightWatchersContext weightWatchersContext = new WeightWatchersContext(optionsBuilder);


            var subscriberService = new SubscriberService(new SubscriberRepository(weightWatchersContext, mapper), mapper);
            //Act - Call the method being tested
            var isEmailExist = await subscriberService.LoginAsync("*****@*****.**", "4545");

            //Assert
            Assert.Equal(isEmailExist, -1);
        }
        public void GetCardId_CardExists_returnSuscriberWithThisCardId()
        {
            var mock = new Mock <ISubscriberRepository>();
            var card = new CardModel()
            {
                id = 1, weight = 200
            };

            mock.Setup(p => p.GetById(1)).Returns(card);
            SubscriberService subscriberService = new SubscriberService(mock.Object);
            var result = subscriberService.GetByIdAsync(1);

            Assert.AreEqual(card, result);
        }
Esempio n. 27
0
        public async System.Threading.Tasks.Task GetCardIdAsync_CardExists_returnSuscriberWithThisCardIdAsync()
        {
            var mock = new Mock <ISubscriberRepository>();
            var card = new CardModel()
            {
                id = 1, weight = 200
            };

            mock.Setup(p => p.GetByIdAsync(1).Result).Returns(card);
            SubscriberService subscriberService = new SubscriberService(mock.Object);
            CardModel         result            = subscriberService.GetByIdAsync(1).Result;

            Assert.Equal(card, result);
        }
Esempio n. 28
0
        /// <summary>
        /// This event registers with the chat server
        /// </summary>
        public void RegisterWithServer()
        {
            SubscriberCallback callback = new SubscriberCallback(SubscriberName);

            callback.Callback = Listen;
            callback.Name     = SubscriberName;

            // Get a message back
            SubscriberMessage message = SubscriberService.Subscribe(callback);

            // if message.Text exists and equals Subscribed
            if ((NullHelper.Exists(message)) && (message.HasText) && (TextHelper.IsEqual(message.Text, "Subscribed")))
            {
                // Set to true
                Connected = true;

                // Set the Id the Server assigned
                this.Id = message.ToId;
            }

            // Convert the Subscribers to Names
            this.Names = SubscriberService.GetSubscriberNames();

            // get the count
            int count = NumericHelper.ParseInteger(message.Data.ToString(), 0, -1);

            // if there are two people online or more
            if (count > 1)
            {
                // send a message to everyone else this user has joined
                SubscriberMessage newMessage = new SubscriberMessage();

                // set the text
                newMessage.FromId          = Id;
                newMessage.FromName        = SubscriberName;
                newMessage.Text            = SubscriberName + " has joined the conversation.";
                newMessage.ToId            = Guid.Empty;
                newMessage.ToName          = "Room";
                newMessage.IsSystemMessage = true;

                // Send the message
                SubscriberService.BroadcastMessage(newMessage);

                // 6.5.2020: Get the Messages as you connect now
                this.Messages = SubscriberService.GetBroadcastMessages(this.Id, DisplayMessagesCount);
            }

            // Update
            Refresh();
        }
Esempio n. 29
0
        public async void GetCardAsync_CardExist_GotCardModel()
        {
            var optionsBuilder = new DbContextOptionsBuilder <WeightWatchersContext>()
                                 .UseSqlServer("Server = C1; Database = WeightWatchersDB ;Trusted_Connection=True; ").Options;
            WeightWatchersContext weightWatchersContext = new WeightWatchersContext(optionsBuilder);


            var subscriberService = new SubscriberService(new SubscriberRepository(weightWatchersContext, mapper), mapper);

            //Act - Call the method being tested
            var card = await subscriberService.GetCardAsync(1);

            //Assert
            Assert.IsType <CardModel>(card);
        }
        public async Task SubscribeAsync_ShouldSubscribe_WhenSubscriberExistsAndConfirmationCodeIsCorrect()
        {
            var subscriberId = Guid.NewGuid().ToString();
            var subscriberConfirmationCode = Guid.NewGuid().ToString();

            await this.dbContext.Subscribers.AddAsync(new Subscriber { Id = subscriberId, ConfirmationCode = subscriberConfirmationCode });

            await this.dbContext.SaveChangesAsync();

            var subscriberService = new SubscriberService(this.dbContext);
            await subscriberService.SubscribeAsync(subscriberId, subscriberConfirmationCode);

            var subscriber = await this.dbContext.Subscribers.FindAsync(subscriberId);

            Assert.True(subscriber.IsConfirmed);
        }
        public async Task UnsubscribeAsync_ShouldThrowInvalidSubscriberException_WhenSubscriberNotExists()
        {
            var subscriberId = Guid.NewGuid().ToString();
            var subscriberConfirmationCode = Guid.NewGuid().ToString();

            await this.dbContext.Subscribers.AddAsync(new Subscriber { Id = subscriberId, ConfirmationCode = subscriberConfirmationCode });

            await this.dbContext.SaveChangesAsync();

            var subscriberService = new SubscriberService(this.dbContext);

            var incorrectId = Guid.NewGuid().ToString();

            Assert.Throws <InvalidSubscriberException>(() =>
                                                       subscriberService.UnsubscribeAsync(incorrectId, subscriberConfirmationCode).GetAwaiter().GetResult());
        }
        public void ProvisionedServicesDictionary_Public_Property_does_not_throw_an_exception_when_billed_services_name_is_null()
        {
            // Arrange
            const string expectedClassName = "VOICE - VOIP";
            const string expectedDescription = "CALLER ID ON TV";
            const string expectedName = "CVCTV";
            var expectedCompositeNameAndDescription = string.Format("({0}) {1}", expectedName, expectedDescription);
            const string expectedElementClass = "childItem";
            const bool expectedExcludedFromSyncedServices = false;
            const string expectedImageUrl = "../../../../Images/warning.png";
            const bool expectedIsSynced = false;

            var provisionedService = new SubscriberService()
            {
                Action = null,
                ClassName = expectedClassName,
                Description = expectedDescription,
                Name = expectedName,
                Type = DAL.DataTransfer.Common.ServiceClassTypeDto.None
            };
            CVoipPhoneServicesViewModelForTests.ProvisionedServicesList.Add(provisionedService);

            var billedService = new SubscriberService()
            {
                Action = null,
                ClassName = null,
                Description = null,
                Name = null,
                Type = DAL.DataTransfer.Common.ServiceClassTypeDto.None
            };
            CVoipPhoneServicesViewModelForTests.BilledServicesList.Add(billedService);

            var actual = new SortedDictionary<string, List<SubscriberService>>();

            // Act and Assert - the test passes if there isn't any exception thrown
            try
            {
                actual = CVoipPhoneServicesViewModelForTests.ProvisionedServicesDictionary;
            }
            catch(Exception ex)
            {
                Assert.Fail("The following exception was thrown{0}{0}{1}", Environment.NewLine, ex);
            }

            Assert.IsNotNull(actual, "The ProvisionedServicesDictionary public property returned null");
            Assert.AreEqual(1, actual.Count, "The ProvisionedServicesDictionary count did not match the expected value");
            Assert.IsTrue(actual.ContainsKey(expectedClassName), "The result doesn't contain the Key of {0}", expectedClassName);

            List<SubscriberService> subscriberServices;
            actual.TryGetValue(expectedClassName, out subscriberServices);

            Assert.IsNotNull(subscriberServices, "The list of services inside ProvisionedServicesDictionary public property returned null");
            Assert.AreEqual(1, subscriberServices.Count, "The subscriber services count did not match the expected value");
            Assert.AreEqual(expectedCompositeNameAndDescription, subscriberServices[0].CompositeNameAndDescription, "The subscriber services CompositeNameAndDescription did not match the expected value");
            Assert.AreEqual(expectedElementClass, subscriberServices[0].ElementClass, "The subscriber services ElementClass did not match the expected value");
            Assert.AreEqual(expectedExcludedFromSyncedServices, subscriberServices[0].ExcludedFromSyncedServices, "The subscriber services ExcludedFromSyncedServices did not match the expected value");
            Assert.AreEqual(expectedImageUrl, subscriberServices[0].ImageUrl, "The subscriber services ImageUrl did not match the expected value");
            Assert.AreEqual(expectedIsSynced, subscriberServices[0].IsSynced, "The subscriber services IsSynced did not match the expected value");
        }
Esempio n. 33
0
 public SubscribersController(IUnitOfWork unitOfWork)
     : base(unitOfWork)
 {
     SubscriberService = new SubscriberService(UnitOfWork);
     GroupService = new GroupService(UnitOfWork);
 }
Esempio n. 34
0
 public SubscriberController()
 {
     SubscriberService = new SubscriberService(UnitOfWork);
 }